#C6839. Select Top Photos
Select Top Photos
Select Top Photos
You are given n photos, each with a unique photo ID and its corresponding memory size. You are also given an integer m which represents the maximum number of photos that can be retained. Your task is to select the top m photos according to the following criteria:
- Photos must be sorted in descending order of their memory size.
- If two photos have the same memory size, they should be sorted by their photo ID in ascending order.
Note: The formulas used in sorting can be represented as follows:
Sort the photos by \( (-memory, id) \) in order.
Print the selected photo IDs in a single line, separated by a space.
inputFormat
The input is given via standard input (stdin) and has the following format:
n m id1 memory1 id2 memory2 ... idn memoryn
Where:
- n is the number of photos.
- m is the maximum number of photos to retain.
- Each of the next n lines contains two integers: the photo ID and its memory size.
outputFormat
The output should be printed to standard output (stdout) as a single line containing the selected photo IDs separated by a space.
## sample5 3
101 200
102 300
103 200
104 500
105 200
104 102 101
</p>