CT44143

Fletcher Counts the signals

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Fletcher inherited the kitchen at the cinnabar mines of Vermilion along with its curious bookkeeping system for signals. Time to make sense of it. 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: 867 282 551733801 42254935 373138968 -475686717 -172841988 -217398045 -50724734 -353118296 956183565 313528594 -527007726 954306068 -427952761 487592742 156109765 134420845 -683444209 -747362014 -608177076 863538364 858870846 -591445875 620374969 -98751302 375998148 -79592922 369130682 835019118 914164978 4085082 -914103244 751287379 -972142019 461939323 -601451264 556386800 -110655303 505550346 -310496082 954657982 -310572253 347126692 448855770 688685687 -377619267 -566677525 -654594616 -657011343 -581560254 -782861032 623918341 736831209 -22829917 358867698 743107686 168470064 -252893912 440207148 -315441454 -417345635 919677928 993548438 -296752008 137533883 338604208 926454816 622837647 267040366 -958465307 -533469427 -17236990 760917792 711089881 593537700 -845065077 -987655197 23672…
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: 1432 570 888951993 -462903432 171400794 -351215262 -722980870 763636739 -655648392 370062490 902532144 38395370 522797959 -228826941 227078104 -605254676 388391374 -5981735 -80138871 -312612727 232104571 -876422199 -362042473 -162337266 946262950 -284579013 567595408 731983895 -101047568 -730856398 -294510986 620909226 -111541799 350429768 -94112117 890539840 -815805174 -568548749 -977190196 63967219 -329016723 23123798 737003486 342391322 386119014 717308060 -418670312 -502203773 -927291886 507350315 -709157396 546656198 229777280 557921709 69712431 10724710 628916625 982288276 477025509 235726690 -641427105 -187514734 -198965811 746070543 -139367549 755597288 -205963422 985636402 918156586 -358185630 885731848 -543444053 301300212 -754128887 989040008 928588721 -676988923 367366126 62579…
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: 31 7 784813047 380695785 -109748708 843302016 -61927869 -788441424 -158928273 -821236900 -352434545 990583873 680535048 -886649744 -264299669 424829446 748947983 290629175 -281995906 -867190041 996867614 -407063672 832984922 -92761659 958871182 -935405716 545138168 -482297975 798455186 -94226971 521035527 -679708802 -761930058
Output: -1 -1 -1 -1 -1 -1 -788441424 -788441424 -352434545 -158928273 -109748708 -109748708 -109748708 -61927869 380695785 380695785 380695785 380695785 424829446 424829446 680535048 680535048 748947983 748947983 748947983 748947983 784813047 784813047 784813047 784813047 784813047

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Fletcher Counts the signals - MEDIUM Coding Problem | CodeTikki