CT58204

The Greyfen Middle So Far

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

Legend says the vault under the foggy moor of Greyfen opens only for a perfect tally of registers. Wheelwright means to find out. 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: 581 482011324 -733457371 -675649053 957970132 -113525270 -167473501 -160643108 401450043 325828513 72752293 -415057450 -760708661 728180999 -282569565 378818263 -423876471 276192585 929667332 183435390 -165112347 949528021 129686914 -898682836 504110325 70159213 -635380351 -135688522 -259487343 -282617063 -134838017 978803116 -859814008 239257622 -743404946 -918276825 -259650766 -819865428 -350788363 -834197776 631070036 980109093 -35189886 -747314556 143012918 -598449517 -419960673 -414779671 -169569470 -377536816 -236769912 669078072 -109645267 950025879 -736834466 274003862 202632707 -708763883 21048724 930240913 -138114582 -242984408 -965532442 -515163068 -540973373 804738410 23893798 -281754584 739808137 273391441 225002972 23392909 -443189686 408506614 -953502381 -418325779 816003319…
Output: 482011324 -733457371 -675649053 -675649053 -113525270 -167473501 -160643108 -160643108 -113525270 -113525270 -113525270 -160643108 -113525270 -160643108 -113525270 -160643108 -113525270 -113525270 72752293 -113525270 72752293 72752293 72752293 72752293 72752293 70159213 70159213 -113525270 -113525270 -134838017 -113525270 -134838017 -113525270 -134838017 -134838017 -135688522 -135688522 -160643108 -160643108 -160643108 -135688522 -135688522 -135688522 -135688522 -135688522 -160643108 -160643108 -165112347 -165112347 -167473501 -165112347 -165112347 -160643108 -165112347 -160643108 -160643108 -160643108 -160643108 -135688522 -138114582 -138114582 -160643108 -160643108 -165112347 -160643108 -160643108 -160643108 -160643108 -138114582 -138114582 -135688522 -138114582 -135688522 -138114582 -13…

Example 2:

Input: 1380 463118844 72998274 -134122151 -630689324 -645208951 -768967766 -706636741 -24747386 598279439 9659932 -648013089 316583645 100977648 638974033 -674068474 407606813 288786653 106205615 368607911 717256672 -265142896 -532852719 487795354 -595871499 43987210 -676586732 -983870740 111135577 -645176553 699169137 -168628870 -197914868 -921455093 -524883317 -580973643 103357729 -930833335 -523233113 715047758 -534368028 -522396609 882745188 29686013 697291929 687443078 -899951399 915364306 -864821117 319863012 -695449013 -374201227 -194856949 -751501921 888639073 -253725940 -921323556 580685778 375769825 -467263647 224521301 21312154 704527087 801063780 -362283482 758945869 191544272 -349262289 -579838911 -148265422 -492756554 745947222 -323322972 -655796033 292965973 762264471 -407624344 -8…
Output: 463118844 72998274 72998274 -134122151 -134122151 -630689324 -630689324 -630689324 -134122151 -134122151 -134122151 -134122151 -24747386 -24747386 -24747386 -24747386 9659932 9659932 72998274 72998274 72998274 9659932 72998274 9659932 43987210 9659932 9659932 9659932 9659932 9659932 9659932 -24747386 -24747386 -134122151 -134122151 -134122151 -134122151 -168628870 -134122151 -168628870 -168628870 -168628870 -134122151 -134122151 -24747386 -134122151 -24747386 -134122151 -24747386 -134122151 -134122151 -168628870 -168628870 -168628870 -168628870 -194856949 -168628870 -168628870 -168628870 -168628870 -134122151 -134122151 -24747386 -134122151 -24747386 -24747386 -24747386 -134122151 -134122151 -148265422 -134122151 -148265422 -148265422 -148265422 -134122151 -148265422 -148265422 -148265422 …

Example 3:

Input: 501 573635982 -922779265 351008548 232307496 -851649819 933869943 -905818992 353077978 -280305227 -519246181 -219813594 -400858329 540103736 918204606 -59279702 956108487 787965699 992498288 466158077 -745943905 867648744 759164410 -435740740 -491583892 -875130804 -778244583 -183760974 -492631916 -889836430 -74551181 10417008 817007885 -258296228 540748839 57437769 -332652435 -714994705 -786715170 844317977 -887920995 600334968 -494967394 -52303752 -483814574 899556312 -981369018 -922815061 757156807 168050455 -726764911 85385696 602485635 453875164 438264718 124842732 538592731 744654028 512556649 -961786650 272922967 100369172 -115002069 398858723 608908835 480530752 618637353 577229464 233656165 -879578665 -961190128 663573036 -276507450 -465184811 -41655796 -982893174 -108519466 532150…
Output: 573635982 -922779265 351008548 232307496 232307496 232307496 232307496 232307496 232307496 -280305227 -219813594 -280305227 -219813594 -219813594 -59279702 -59279702 232307496 232307496 351008548 232307496 351008548 351008548 351008548 232307496 232307496 -59279702 -59279702 -183760974 -183760974 -183760974 -74551181 -74551181 -74551181 -74551181 -59279702 -74551181 -74551181 -183760974 -74551181 -183760974 -74551181 -183760974 -74551181 -183760974 -74551181 -183760974 -183760974 -183760974 -74551181 -183760974 -74551181 -74551181 -59279702 -59279702 -52303752 -52303752 10417008 10417008 10417008 10417008 57437769 10417008 57437769 57437769 85385696 85385696 100369172 100369172 100369172 85385696 100369172 85385696 85385696 57437769 57437769 10417008 57437769 57437769 57437769 57437769 853…

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
The Greyfen Middle So Far - MEDIUM Coding Problem | CodeTikki