#K13061. Sort Activities by Priority

    ID: 23829 Type: Default 1000ms 256MiB

Sort Activities by Priority

Sort Activities by Priority

You are given a list of n activities. Each activity is represented by a string in the format name,priority, where name is a descriptive name of the activity and priority is an integer representing its priority.

Your task is to sort the activities in descending order of their priority. In case two or more activities have the same priority, they should be sorted in ascending alphabetical order by their name.

The sorting criteria can be mathematically represented as:

\( (p_1, s_1) \succ (p_2, s_2) \iff (p_1 > p_2) \vee (p_1 = p_2 \wedge s_1 < s_2) \),

where \(p\) denotes the priority and \(s\) denotes the activity name.

inputFormat

The first line of the input contains an integer n denoting the number of activities. The following n lines each contain a string of the format name,priority.

For example:

3
Write report,2
Morning Exercise,5
Team Meeting,5

outputFormat

Output the sorted list of activities, one activity per line, following the described order.

For the example input above, the output should be:

Morning Exercise,5
Team Meeting,5
Write report,2
## sample
3
Write report,2
Morning Exercise,5
Team Meeting,5
Morning Exercise,5

Team Meeting,5 Write report,2

</p>