CT46700

Sailor Counts the ledgers

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Legend says the vault under the snowberry thicket of Winterholt opens only for a perfect tally of ledgers. Sailor means to find out. Task: For every contiguous window of length k, print the maximum. Input format: First line: n and k. Second line: n integers. Output format: Print n-k+1 maxima space-separated. Constraints: 1 <= k <= n <= 4000; -10^9 <= a[i] <= 10^9.

Example 1:

Input: 3232 1206 764288928 89587908 -703819932 482200947 -582315068 634445865 27436428 -153480395 766204255 360054630 -640107357 -294934773 95233509 668617024 103394661 -883504742 599201480 -228279083 -210994732 836521155 -969896414 241231403 211004300 116004820 103634035 -621740643 419922322 801056825 138021482 933676489 -965600964 -650462144 87401525 -247739111 230808216 213564263 870295887 46274728 329110788 792338389 92514816 697101222 45875841 528466480 -639035106 -615589249 -486450307 -262557424 -811481456 630276150 -452186162 443895795 -234825153 16805511 -453571130 394640618 954154805 851765248 451377280 -304032336 119718323 -605466274 231402604 928234518 827561162 -113304840 -675671844 -816244220 812097092 931990112 -252425830 125111616 -248359367 -255347014 -163553593 359677555 -3820939…
Output: 999285634 999285634 999285634 999285634 999285634 999285634 999285634 999285634 999285634 999285634 999285634 999285634 999285634 999285634 999285634 999285634 999285634 999285634 999285634 999285634 999285634 999285634 999285634 999285634 999285634 999285634 999285634 999285634 999285634 999285634 999285634 999285634 999285634 999285634 999285634 999285634 999285634 999285634 999285634 999285634 999285634 999285634 999285634 999285634 999285634 999285634 999285634 999285634 999285634 999285634 999285634 999285634 999285634 999285634 999285634 999285634 999285634 999285634 999285634 999285634 999285634 999285634 999285634 999285634 999285634 999285634 999285634 999285634 999285634 999285634 999285634 999285634 999285634 999285634 999285634 999285634 999285634 999285634 999285634 999285634 …

Example 2:

Input: 3409 694 651614563 -403693555 -360924497 -796714141 -504115606 477499434 287099480 -742689324 -871262881 -112137365 -861065688 877416739 635299696 -618677841 845959532 840632118 -811141276 -832359009 -523041997 59512467 -123628221 -164978113 330785258 -89836719 734840988 587511051 -199867012 717330055 -724225726 -425078124 -922223837 875501448 -741426530 3933529 834769782 -786559253 -185625613 -678590972 555519723 154825025 534759788 -512941882 -106371903 -380777675 -53881828 -787345040 7599107 320238862 794648266 -950930551 -602391324 226220178 -652694522 -170970986 -777575765 -976421104 732706297 -22795102 -689051482 646181489 984634656 -946903406 -28181764 822922642 -814681135 426535883 894323692 -747318698 187390741 -96970241 849785805 669832060 799738931 214462638 358413180 -493503789…
Output: 999959462 999959462 999959462 999959462 999959462 999959462 999959462 999959462 999959462 999959462 999959462 999959462 999959462 999959462 999959462 999959462 999959462 999959462 999959462 999959462 999959462 999959462 999959462 999959462 999959462 999959462 999959462 999959462 999959462 999959462 999959462 999959462 999959462 999959462 999959462 999959462 999959462 999959462 999959462 999959462 999959462 999959462 999959462 999959462 999959462 999959462 999959462 999959462 999959462 999959462 999959462 999959462 999959462 999959462 999959462 999959462 999959462 999959462 999959462 999959462 999959462 999959462 999959462 999959462 999959462 999959462 999959462 999959462 999959462 999959462 999959462 999959462 999959462 999959462 999959462 999959462 999959462 999959462 999959462 999959462 …

Example 3:

Input: 2938 2710 -603213097 8000645 -854972165 -872988166 -201412163 52925258 -838531890 -676495210 -678674442 154973603 -652695802 123866308 576950528 798382131 -80634786 515323971 959774655 -615353539 -585976913 -459244125 671431068 393944962 -135681657 563869736 -85610720 -292542157 701001418 286330443 -869717186 -842671694 -727491007 -525023064 481007364 -744758235 219478972 -746112399 -744313045 851633200 -922135606 -747158441 -664932278 -591408157 -173559313 -655795881 -976034927 589877169 630415642 -496732112 -443148606 798704448 459368925 898042113 -421437404 -318493803 801567037 -341532336 -309745613 -123900471 -460034744 844348254 -896932349 -259629524 -237155827 -776303797 -383042122 804164744 -145424395 -651068959 847399964 968486089 -142417517 -360748328 -748090476 995384487 -7640184…
Output: 998467692 998467692 998467692 998467692 998467692 998467692 998467692 998467692 998467692 998467692 998467692 998467692 998467692 998467692 998467692 998467692 998467692 998467692 998467692 998467692 998467692 998467692 998467692 998467692 998467692 998467692 998467692 998467692 998467692 998467692 998467692 998467692 998467692 998467692 998467692 998467692 998467692 998467692 998467692 998467692 998467692 998467692 998467692 998467692 998467692 998467692 998467692 998467692 998467692 998467692 998467692 998467692 998467692 998467692 998467692 998467692 998467692 998467692 998467692 998467692 998467692 998467692 998467692 998467692 998467692 998467692 998467692 998467692 998467692 998467692 998467692 998467692 998467692 998467692 998467692 998467692 998467692 998467692 998467692 998467692 …

Constraints:

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

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