459. Queue Reconstruction by Height
MediumGreedySorting
Each person is (h, k): height h, with exactly k people of height ≥ h in front. Reconstruct the queue and print one "h k" per line, front to back.
Input format
Line 1: n Next n lines: h k
Output format
The queue, one person per line.
Example 1
Input
6 7 0 4 4 7 1 5 0 6 1 5 2
Output
5 0 7 0 5 2 6 1 4 4 7 1
Example 2
Input
6 6 0 5 0 4 0 3 2 2 2 1 4
Output
4 0 5 0 2 2 3 2 1 4 6 0
Constraints
1 ≤ n ≤ 2000
Read input from standard input and print the answer to standard output. Your code is judged against 3 test cases, most of them hidden.
Loading the MyLoginn IDE…