#t550. 病人排队
病人排队
Patient Queue
Problem Description
Write a program that orders registered patients for seeing the doctor according to the following rules:
- Elderly patients (age ) are seen before non-elderly patients.
- Among the elderly, order by age descending; patients with the same age are ordered by their registration order.
- Non-elderly patients are ordered by their registration order.
Input Format
The first line contains a positive integer (), the number of patients.
Then, in registration order, each line contains one patient's information: a string of length less than as the patient's ID (each patient's ID is distinct and consists only of digits and letters), and an integer as the patient's age, separated by a single space.
Output Format
Output the patients' IDs in the arranged order, one per line.
Sample Input
5
021075 40
004003 15
010158 67
021033 75
102012 30
Sample Output
021033
010158
021075
004003
102012
Sample Explanation
There are patients in the sample. Elderly means age not less than , so the patient with age (ID 010158) and the patient with age (ID 021033) are elderly. The elderly are ordered by age descending: ID 021033 (age ) comes before ID 010158 (age ). The non-elderly are ordered by registration order: ID 021075 (age ), ID 004003 (age ), ID 102012 (age ). Merging the elderly and non-elderly by the rules gives the order: ID 021033, ID 010158, ID 021075, ID 004003, ID 102012. Hence the output above.
Constraints
- , where is the number of patients.
- Each patient's ID has length less than , consists only of digits and letters, and all patients' IDs are distinct.
- Each patient's age is an integer.