IntuitOA #2
The Chosen Ones — Queue Iterations
EasyJudge-ready
Topics (AI-labelled)SimulationStacks & Heaps
Given n non-negative integers and an integer x, perform x rounds. In each round, take up to x numbers from the front of the queue and select the maximum among them; on ties, select the one closest to the front. Decrease each of the other values by 1 (to a minimum of 0) and put them back at the end of the queue in their original relative order. Output the original 1-based indices of the selected elements.
Input
The first line contains n and x, and the second line contains n non-negative integers. Site limits: 1≤x≤n≤1000, 0≤queue[i]≤10⁹. x≤n is a site limit that guarantees the queue is non-empty at the start of every round.
Output
Output the original indices of the x selected elements in the order they were selected, separated by spaces.
Example 1
Input:
7 5
1 2 2 3 4 5 5
Output:
5 6 7 4 1
Example 2
Input:
1 1
0
Output:
1
Example 3
Input:
2 1
0 0
Output:
1
Example notes
The original sample input came without an output. Simulating round by round according to the original text, the indices selected for that sample are 5 6 7 4 1.
Editorial
Loading solution…