Numbers arrive one at a time and are added to a growing collection. After each addition, report the k-th largest value currently in the collection (counting duplicates by position). If fewer than k numbers have been added so far, report the token - instead.
Line 1: two integers k and q, where q is the number of additions.
Line 2: q space-separated integers, the numbers in arrival order.
q space-separated tokens on one line: after each addition, the current k-th largest value, or - if fewer than k numbers exist.
Example 1
Input
2 5 5 3 8 1 9
Expected
- 3 5 5 8
Explanation
After 5: only one number, so '-'. After 3: 2nd largest is 3. After 8: 2nd largest is 5. After 1: 2nd largest is still 5. After 9: 2nd largest is 8. Output: - 3 5 5 8.
Example 2
Input
1 3 4 7 2
Expected
4 7 7
Explanation
With k=1 the answer is the running maximum: after 4 it is 4, after 7 it is 7, after 2 it is still 7.
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 →