During a qualifying session, n racers each cross the timing line once and post a single best lap time. For every racer, the stewards need that racer's deficit count: the number of racers in the same session whose lap time was strictly faster (a smaller number) than that racer's own time. Racers who tied on time never contribute to each other's deficit count.
Given the lap times in the order the racers crossed the timing line, compute the deficit count for every racer.
Line 1: a single integer n, the number of racers. Line 2: n integers time[0], time[1], ..., time[n-1] separated by single spaces, the lap time of each racer in hundredths of a second, listed in the order they crossed the timing line.
Print n integers separated by single spaces, in the same order as the input: the i-th value is the number of racers whose lap time is strictly smaller than time[i].
2 <= n <= 200000 0 <= time[i] <= 1000000
Example 1
Input
4 8 1 2 2
Expected
3 0 1 1
Explanation
Racer 0 (time 8) has 3 racers strictly faster (1, 2, 2). Racer 1 (time 1) has 0 racers strictly faster. Racer 2 (time 2) has 1 racer strictly faster (the time-1 racer); racer 3 (also time 2) likewise has 1. Output: 3 0 1 1.
Example 2
Input
5 7 7 7 7 7
Expected
0 0 0 0 0
Explanation
Every racer posted the identical time 7, so no racer has anyone strictly faster than them. Output: 0 0 0 0 0.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →