#K42342. Optimal Ticket Order
Optimal Ticket Order
Optimal Ticket Order
You are given n tickets and a time interval m (in minutes). Each ticket has an associated priority. The optimal order for resolving the tickets is determined by sorting them primarily in descending order of priority and, in case of equal priorities, by their original index in ascending order.
Formally, if the tickets are numbered from 1 to n and the priority of the i-th ticket is given by \(p_i\), then the order should satisfy:
[ \text{for any two tickets } i \text{ and } j, \text{ if } p_i > p_j, \text{ then ticket } i \text{ comes before ticket } j. ]
If \(p_i = p_j\), then the ticket with the smaller index appears first. Note that the time interval m is provided for context but does not affect the ordering.
inputFormat
The input is read from standard input (stdin) and consists of two lines:
- The first line contains two space-separated integers \(n\) and \(m\), where \(n\) is the number of tickets and \(m\) is the time interval in minutes.
- The second line contains \(n\) space-separated integers representing the priority levels of each ticket.
outputFormat
Output the optimal ticket order as a sequence of ticket indices separated by spaces. The order should reflect the descending order of priorities, with ties broken by increasing ticket index.
## sample5 15
3 5 2 4 1
2 4 1 3 5