CT57327

Boris and the Sunlit ledgers

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

Every season at the ivory gates of Alabast, someone must settle a dispute between crews. This year the task falls to Boris, armed only with the ledgers register. Task: After each arrival, print the median of the stream so far — defined as the element at sorted position ceil(k/2) (1-based). Input format: First line: n. Second line: n integers. Output format: Print n medians space-separated. Constraints: 1 <= n <= 4000; -10^9 <= a[i] <= 10^9.

Example 1:

Input: 3636 174828255 217220320 50804887 224862203 367239458 -277118838 251246528 -669524771 -434089661 -403635500 -691137447 -461181817 522335280 848435128 -627074274 242137297 -298517869 -662108315 86315672 171443671 -928050825 301356899 -517901612 249619773 -733210128 788533016 -20950854 -919372933 640903550 581503794 722801501 -973853607 864844405 930984433 -719914517 -247497672 -297647032 125648516 -651520121 -585565558 109621511 -899795467 -455709936 510178516 840347835 467524404 695681754 839718019 -710403796 -258962542 842092003 -29384901 -162382157 783939411 461091551 -319888022 -36962625 554411815 289880985 16727368 -320730082 863019008 495887446 -251540436 -883531477 73000582 -198171109 -827081446 488314658 282035785 500908263 355593692 991205577 -571977533 -958824424 204282325 2029833…
Output: 174828255 174828255 174828255 174828255 217220320 174828255 217220320 174828255 174828255 50804887 50804887 -277118838 50804887 50804887 50804887 50804887 50804887 -277118838 50804887 50804887 50804887 50804887 50804887 50804887 50804887 50804887 50804887 -20950854 50804887 50804887 86315672 50804887 86315672 86315672 86315672 50804887 50804887 50804887 50804887 -20950854 50804887 -20950854 -20950854 -20950854 50804887 50804887 86315672 86315672 86315672 50804887 86315672 50804887 50804887 50804887 86315672 50804887 50804887 50804887 86315672 50804887 50804887 50804887 86315672 50804887 50804887 50804887 50804887 16727368 50804887 50804887 73000582 73000582 86315672 73000582 73000582 73000582 86315672 73000582 86315672 73000582 73000582 50804887 73000582 50804887 50804887 16727368 16727368…

Example 2:

Input: 3732 -553598006 -18729338 927600361 -411355059 -834889290 55665575 -400565907 -996655351 784781230 -884708168 -750612613 634417942 -389890549 61205483 -3945984 492006882 -592404321 525016173 -431573528 584367283 -422123474 -944908536 692741482 732082547 157284610 -487720502 -556688523 710402519 -926312292 57959908 66741341 -240118592 846257116 951485857 -384889082 760953232 -942500299 220121941 909514536 -317101956 -741574475 -59026266 786209548 967849721 -101649831 -80345471 -286858324 900591174 -666916031 998996953 212607255 106573101 113166992 -581931048 334456947 -356772638 60638080 -519014271 782420109 -662730980 -399835235 491979205 -765708071 -960557525 -946486606 703987143 445054323 -239877157 458681837 469232672 -268739010 713263292 -708016794 45045420 962748940 434039198 17239569…
Output: -553598006 -553598006 -18729338 -411355059 -411355059 -411355059 -400565907 -411355059 -400565907 -411355059 -411355059 -411355059 -400565907 -400565907 -389890549 -389890549 -389890549 -389890549 -389890549 -389890549 -389890549 -400565907 -389890549 -389890549 -18729338 -389890549 -389890549 -389890549 -389890549 -389890549 -18729338 -240118592 -18729338 -18729338 -18729338 -18729338 -18729338 -18729338 -3945984 -18729338 -18729338 -59026266 -18729338 -18729338 -18729338 -59026266 -59026266 -59026266 -59026266 -59026266 -18729338 -18729338 -3945984 -18729338 -3945984 -18729338 -3945984 -18729338 -3945984 -18729338 -18729338 -18729338 -18729338 -59026266 -59026266 -59026266 -18729338 -59026266 -18729338 -18729338 -18729338 -18729338 -18729338 -18729338 -3945984 -3945984 45045420 -3945984 …

Example 3:

Input: 252 210634602 669713664 -57266019 445668297 788705346 -473489926 -854093484 -953782679 763978217 -78970205 -871606637 -453712223 -935303069 -843279089 -458138797 -564354227 -458589147 -966197881 -709010418 52755544 -951565716 817255951 890410082 -514988682 -159934303 -88079867 38912999 371172470 -845956113 -243024518 -938729207 -311486309 295436558 -847438064 884577737 999579149 685249588 187873561 488619035 171259368 425412103 -310588476 340152826 -168427966 -441291534 -801902750 -281022539 -593717814 868782619 404507176 -323752095 9193023 -864468388 11957431 -175079044 -512966319 -399618244 -430435574 -632616528 911437128 -412767279 -366222000 -468573992 361771301 -248360800 161030859 -919154012 -755917714 -40161840 -162748257 717196974 912025931 383377334 129902463 -724565245 58414963 -…
Output: 210634602 210634602 210634602 210634602 445668297 210634602 210634602 -57266019 210634602 -57266019 -57266019 -78970205 -78970205 -453712223 -453712223 -458138797 -458138797 -458589147 -458589147 -458589147 -458589147 -458589147 -458138797 -458589147 -458138797 -458138797 -453712223 -453712223 -453712223 -453712223 -453712223 -453712223 -311486309 -453712223 -311486309 -311486309 -243024518 -243024518 -159934303 -159934303 -88079867 -159934303 -88079867 -159934303 -159934303 -168427966 -168427966 -243024518 -168427966 -168427966 -168427966 -168427966 -168427966 -168427966 -168427966 -175079044 -175079044 -243024518 -243024518 -243024518 -243024518 -281022539 -281022539 -281022539 -248360800 -248360800 -248360800 -281022539 -248360800 -248360800 -243024518 -243024518 -175079044 -175079044 -…

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Boris and the Sunlit ledgers - MEDIUM Coding Problem | CodeTikki