Largest Element In A Stream

easy
1.Given an input stream of n integers, find the kth largest element for each element in the stream. 2. Input is handled for you 3. It is a functional problem ,please do not modify main()

Input Format

First line contains two space separated integers n and k. Second line contains n space separated values of the array.

Output Format

Print the space separated values denoting the kth largest element at each insertion, if the kth largest element at a particular insertion in the stream doesn't exist print -1.

Constraints

1 <= K <= n
 1 <= n <= 106
 1 <= stream[] <= 105

Notice

Try First, Check Solution later

1. You should first read the question and watch the question video.
2. Think of a solution approach, then try and submit the question on editor tab.
3. We strongly advise you to watch the solution video for prescribed approach.

Example

Input
84 47
778 916 794 336 387 493 650 422 363 28 691 60 764 927 541 427 173 737 212 369 568 430 783 531 863 124 68 136 930 803 23 59 70 168 394 457 12 43 230 374 422 920 785 538 199 325 316 371 414 527 92 981 957 874 863 171 997 282 306 926 85 328 337 506 847 730 314 858 125 896 583 546 815 368 435 365 44 751 88 809 277 179 789 585
Output
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 12 23 28 43 59 60 68 70 92 124 136 168 171 173 173 199 212 230 282 306 314 316 316 325 328 336 337 363 368 368 368 369 369 371 371 371 374 387
Previous
Kth Distinct Element
Next
Pepcoding New System

Related Questions