CT51381

Vani's Ledger of beacons

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Legend says the vault under the lantern reef of Glowtide opens only for a perfect tally of beacons. Vani means to find out. Task: As values arrive one by one, after each arrival print the k-th largest seen so far, or -1 while fewer than k values exist. Input format: First line: n and k. Second line: n integers. Output format: Print n answers space-separated. Constraints: 1 <= k <= n <= 4000; -10^9 <= a[i] <= 10^9.

Example 1:

Input: 715 355 814756381 581123314 951417951 966847699 531154500 -795335459 -847104181 611034172 -635454701 41536844 247735103 557009416 327978620 -699326113 817434391 -605847661 235975580 103356847 784449754 717154338 -527361218 905176628 -393310513 21509726 -589037590 -719415929 941225173 685816266 140042638 409359868 -581595860 -868244305 -609646307 -27535179 400754666 -133892846 367295341 581179373 568794345 330890291 39848627 102809062 -363562515 8273529 935071246 -778840704 -564177234 -846457930 -588499437 -948158066 108114599 -325669006 766051519 694942313 -456290791 254789888 -25473313 -681972429 661022555 470904449 998576305 832129075 -922335091 -933411539 -253802947 873238536 838038238 -247667983 -193648296 -939591685 -286283927 715615204 -750895037 -169848916 256498292 -138605624 -8159…
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 -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 -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 -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 -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 -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…

Example 2:

Input: 779 268 -66835267 261213930 -263272690 40522273 -222251437 193782643 -263519788 -448869099 -280326238 33049984 278339328 400577295 148501292 788284152 -481737186 493306902 517314722 -488248293 234327170 760284726 480538891 383484473 -782716228 253185226 -746041933 -272377105 969498368 -92506460 246613260 -89214334 818402967 -812288130 765557973 650967976 797899648 -349514612 -142450751 487277979 -179497012 -339829151 901825539 -406501559 148493907 664146321 870864308 -420102031 -279361332 -990769286 396956392 -781300313 84641065 -923093074 617363780 -143564227 490223841 436454825 850837394 976213947 -627138606 535292582 662357984 -411317253 192598541 -250562799 307373769 -336108900 -705507728 -694694871 392854405 -464712835 408057387 231495486 379687116 3515411 -86567404 835383820 -1754154…
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 -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 -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 -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 -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 -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…

Example 3:

Input: 16 4 614812753 -52749480 76327218 1351644 -765684098 -344430529 953638680 273233519 863113064 -825443585 835882777 324715923 -504559998 815028994 158910778 840217064
Output: -1 -1 -1 -52749480 -52749480 -52749480 1351644 76327218 273233519 273233519 614812753 614812753 614812753 815028994 815028994 835882777

Constraints:

1 <= k <= n <= 4000; -10^9 <= a[i] <= 10^9.

Loading...
Test Cases:No test cases
No test cases available.
Vani's Ledger of beacons - MEDIUM Coding Problem | CodeTikki