CT44901

Emeric's marks K-th So Far

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The harbor bell rings at the boar woods of Tuskmore; Emeric weighs the day's marks manifests and starts the calculations. 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: 262 92 475076051 -194666705 832871884 281113519 -81622722 -13298216 -271796251 631941279 787191463 -369327788 -137000415 636864503 139938248 675401029 -559426591 644556424 212382947 955975042 632277163 -55379059 -200177132 -97911426 -654399180 -857388289 -627191475 516185013 594907678 437654067 -744399325 -628320504 970414279 -833168098 -745608576 56370812 -903231866 -233713910 -239653612 -58961858 -91772870 231627125 262824863 786660264 399028395 -438317004 -781711138 -547022054 133390567 125172850 -216453261 667617763 -293252455 786822816 -821358073 773454987 180724222 229500155 -983812824 -824403668 -56184594 864417934 147359677 91400973 -377837490 -625272534 -81179801 707059339 16570816 856192384 602181480 -296874006 522782351 150052962 703575772 -288439596 -254262115 120523025 -383075…
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 -983812824 -903231866 -857388289 -833168098 -824403668 -821358073 -781711138 -745608576 -745608576 -745608576 -744399325 -654399180 -628320504 -627191475 -625272534 -559426591 -547022054 -438317004 -438317004 -425382277 -412704619 -407278948 -405982801 -405982801 -383075999 -383075999 -377837490 -377837490 -369327788 -369327788 -369327788 -358612548 -296874006 -293252455 -288439596 -271796251 -271796251 -271796251 -254262115 -239653612 -233713910 -228953390 -216453261 -216453261 -211728285 -200177132 -200177132 -194666705…

Example 2:

Input: 3952 2480 430498856 -619067281 -819069384 -453789752 461260026 -601531753 -859222436 -549447570 -527406190 -896457482 -404703066 -574156577 -979483741 405840886 261629312 -351617669 217624642 -427220861 -117559962 -739791137 724678078 -378800413 878190285 874918067 503373128 882630386 -127786343 260453030 380130125 910063001 72718488 -685586634 172925164 -574217358 805505184 -855028244 -809488563 916340174 -802829139 -54638859 800291022 -56741623 990225546 -255287914 -490801557 9956455 -48693850 205016095 181333631 19894530 868124259 276693950 214044402 143245792 -189920697 174205439 -968337911 -40167267 718517163 214817041 411815009 671661999 206553162 -251492560 50283129 -515738037 -233058198 601880012 -852919863 -727746044 -526813961 -636923893 -806202491 -582291513 -665916324 -94108561…
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: 2380 34 11613286 -991069658 146919730 731474948 642784653 -797271002 -155540148 957622546 186407801 -234248802 -472573711 -817314895 96979843 160789656 -575261492 -275509651 -593030570 -259489108 -249853742 -746703713 -68304411 210998476 918995796 584214301 -791434984 501498684 -997676179 530061656 479490671 -278153595 575890745 736860814 -70943959 194134826 -423585631 -819834552 -98763240 -506214273 -454222373 294859980 150644471 229799406 878174467 783471440 -992558349 202615834 73976199 845102029 863917128 -567593378 432754106 635677729 -944338280 -195443163 -719006369 -408851473 373448935 575871755 743662937 -479854890 -441979312 731841030 693787149 762415519 203938309 995123916 273875182 -587347368 209809424 -932506149 3162403 496254385 399051784 -177699724 -865253285 -75952061 962972…
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 -997676179 -991069658 -819834552 -817314895 -797271002 -791434984 -746703713 -593030570 -575261492 -506214273 -472573711 -472573711 -454222373 -423585631 -278153595 -275509651 -275509651 -259489108 -249853742 -249853742 -234248802 -234248802 -234248802 -195443163 -155540148 -98763240 -98763240 -98763240 -70943959 -68304411 11613286 73976199 96979843 146919730 146919730 150644471 150644471 150644471 160789656 186407801 186407801 186407801 186407801 194134826 194134826 194134826 202615834 203938309 209809424 209809424 209809424 209809424 209809424 209809424 210998476 210998476 210998476 229799406 229799406 229799406 273875182 273875182 273875182 294859980 294859980 373448935 373448935 373448935…

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Emeric's marks K-th So Far - MEDIUM Coding Problem | CodeTikki