CT51492

Granite ledgers K-th So Far

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Sahil the valuer watches over the shale slopes of Greystone's stores of ledgers. A careful computation stands between order and chaos. 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: 290 15 -89877742 820811465 -726936844 660821721 -789001627 -245175523 -948786063 -897805222 982317553 -337359803 936466527 -774884546 395467460 304612411 532874168 -173750410 120454231 510644474 782599964 242204609 -864917469 -932076732 525903890 -342226054 78807940 701111419 -99577786 742647215 -892433477 -845114530 -920554201 826729060 -390492569 -187941986 414377129 -905203103 -348512562 -33178922 -842583139 573606515 839338076 900857475 -96933734 785700949 935798899 845651634 850022404 402359694 153116897 901804801 -752131088 -169952970 -188614910 -26438803 -654116839 65057009 87386933 -592121738 -636749628 208244935 945468918 254048102 -458917496 -102348765 -858610722 722000269 -16467149 70986666 -527473003 970590332 -993207776 554176429 960185998 266676624 477697762 826934946 -576164…
Output: -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -948786063 -897805222 -789001627 -774884546 -726936844 -337359803 -337359803 -337359803 -245175523 -245175523 -173750410 -89877742 -89877742 78807940 78807940 78807940 78807940 120454231 120454231 120454231 242204609 242204609 242204609 242204609 242204609 304612411 395467460 414377129 414377129 510644474 525903890 532874168 573606515 573606515 573606515 660821721 660821721 660821721 660821721 660821721 660821721 660821721 660821721 660821721 660821721 660821721 701111419 701111419 701111419 701111419 701111419 722000269 722000269 722000269 722000269 742647215 742647215 742647215 782599964 782599964 782599964 785700949 785700949 785700949 785700949 785700949 785700949 785700949 785700949 787457284 787457284 787457284 787457284 787457284 820811465 8…

Example 2:

Input: 2423 96 -920393974 -346131609 836776332 -697513488 -10641248 -598595785 914527771 -515259352 803987537 151428096 -424340758 910976505 -507607874 -557058404 -645513524 -4416850 -708400885 930025356 802087237 -319009646 168826257 771983899 -505588124 585439893 -203231695 -986258282 141359866 -365071011 624205035 181674529 -642123162 165196697 271655003 -990524010 828339874 125875047 950028324 -240056465 -562789729 -717462695 -379736810 -838884342 -684950264 -833079460 547950876 884291336 228414570 77085257 -342491866 -629298338 -486325130 949701364 -935449500 -338830557 -377736049 -355313651 -193504427 -745961540 587744900 -520264412 904071406 -70876454 126376749 -960657447 453894292 -628831464 165193966 218930264 403888777 839275767 721790354 -51598779 -473158601 799137793 968821779 7780695…
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 -990524010 -986258282 -960657447 -940772186 -935449500 -920393974 -838884342 -833079460 -745961540 -717462695 -708400885 -708400885 -697513488 -684950264 -684950264 -645513524 -642123162 -629298338 -628831464 -598595785 -598595785 -562789729 -557058404 -557058404 -557058404 -557058404 -557058404 -557058404 -520264412 -515259352 -507607874 -507607874 -505588124 -505588124 -505588124 -486325130 -484025718 -473158601 -455736824 -449345551 -424340758 -387046216 -384847183 -379736810 -379736810 -377736049 -37773604…

Example 3:

Input: 2878 798 25487092 -591937644 406064205 545210351 887297406 922222871 193674808 -886383881 195728788 -719687448 929058172 606757406 -505548289 80767630 353357404 603142174 749374108 -111997644 108491134 -361953491 461683577 -222949122 603378402 484533769 -598814599 485974243 -83884819 448866088 -794207997 -568872758 675293603 -27755042 733922945 299330946 109121512 918055959 -258002302 693559342 -244038688 -412163877 40661056 33517674 233410462 669905297 161259883 -326601745 -822726526 100061063 -414683228 -885944933 896024884 -473585546 -678739945 -715364378 -5624946 -738224972 633189917 202427166 242355967 -972162958 188875641 568394871 165150526 228773728 910245930 -578125806 -258364136 629014111 -354008568 -630981480 498542504 2033663 76287718 203528337 306007453 180707117 -404758844 81…
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…

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Granite ledgers K-th So Far - MEDIUM Coding Problem | CodeTikki