CT36228

Theo's Misty registers

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Deep in the shale slopes of Greystone, Theo studies rows of registers entries. One clean number will settle the guild's oldest argument. 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: 3548 425 -426879266 767541782 44725871 -971302977 493925889 -983087521 127973248 -792381232 730620668 525457133 637346244 -48265889 158152099 833560178 526760206 -813113054 378536835 -846647097 -538712731 424130089 -718281476 -173723750 670559078 993395925 -875113519 248291957 168844412 -591691546 -758165275 -674521279 402562646 -914319608 556201813 -86523957 -60871882 -410115773 275096472 297418219 -91985750 -151240610 364708818 -363023291 907215526 182557802 961431997 100160718 -988583267 -924577833 -888543905 -466123341 166398545 95862849 -792785464 -96437641 -596850210 143334093 -749525752 -453150172 132988533 -464292824 251305155 280496184 -681443572 842039247 -726173987 384503470 94203905 -785561119 -363713730 983244993 -995279225 -196698374 -590896820 -57755410 -287865043 870826871 …
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: 360 223 561607858 117706250 -517557022 -431613940 -741327887 796278305 318423770 -389825277 62289008 358297307 110274994 659560016 -182396558 -891856190 121891768 625034226 -520202598 -244764858 -849088244 678562963 -609252451 -964487720 261787238 -832789922 319098454 -250549358 -535419040 436236391 551843829 754562930 -98061194 -848775034 -557344331 763119075 -332304890 653565635 -362363956 -209246578 -785630934 203984152 108783409 -260522121 651799587 777635746 -994569876 -3667262 674053807 94692810 -267002889 -167006283 -359305220 922463025 149975453 -100184460 -724609816 -904483687 -791622214 -89785699 926641367 321774514 -564774257 -607892948 941083454 -524357588 -537343142 -146741010 621062258 -459627647 45010346 -39536178 593344015 554636023 726015723 -335836939 -468002428 587168589…
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 -999380685 -994569876 -970859659 -964487720 -934024718 -926861926 -922176043 -904483687 -892283208 -891856190 -888631264 -884400165 -8…

Example 3:

Input: 12 5 733714264 -731105278 346455083 -685152793 523603662 -503307522 -845762324 617228763 -624114539 996017828 -963309548 -946682628
Output: -1 -1 -1 -1 -731105278 -685152793 -685152793 -503307522 -503307522 346455083 346455083 346455083

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Theo's Misty registers - MEDIUM Coding Problem | CodeTikki