CT64184

Ivo's ledgers Middle So Far

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

Morning light hits the pearl fisheries of Nacre Bay as Ivo unrolls the day's manifest of ledgers. The tally will decide the next shipment. 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: 324 414967269 603497972 850368568 -811668633 559465648 799213832 137336008 -459309193 797818096 -920719608 -594363766 831276479 -766812097 532381167 619845319 618071728 -793222595 -566041259 -484637290 -171204779 107095589 643314861 580853014 807616930 780154235 6660819 -99625649 782029442 656218673 -922124121 660203520 -480806169 -944502170 36319953 -795635245 -45910557 -19924959 -962844794 85900135 648738712 -579565753 -862794149 -999068332 566284382 803497089 -910285990 -888962738 909677119 204271318 126929386 448314798 -260172387 471136895 -383472178 -168785360 496549652 824552586 -374766195 181198928 124809427 71240337 520358415 -859547259 -829748711 464380704 921288955 -477908389 381381720 -234640817 -429937848 687841405 269581925 -628260125 -626488342 236734204 906327561 369431966 1…
Output: 414967269 414967269 603497972 414967269 559465648 559465648 559465648 414967269 559465648 414967269 414967269 414967269 414967269 414967269 532381167 532381167 532381167 414967269 414967269 137336008 137336008 137336008 414967269 414967269 532381167 414967269 414967269 414967269 532381167 414967269 532381167 414967269 414967269 137336008 137336008 107095589 107095589 36319953 85900135 85900135 85900135 36319953 36319953 36319953 85900135 36319953 36319953 36319953 85900135 85900135 107095589 85900135 107095589 85900135 85900135 85900135 107095589 85900135 107095589 107095589 107095589 107095589 107095589 85900135 107095589 107095589 107095589 107095589 107095589 85900135 107095589 107095589 107095589 85900135 107095589 107095589 124809427 124809427 126929386 124809427 124809427 107095589 1…

Example 2:

Input: 3450 56975303 -848964344 -801894430 -109799345 -512342231 904550936 -29771462 -139128947 -809375607 -852708055 552815853 243582224 -119136935 -581007985 -604944266 789450893 246921372 956366807 670529133 309559023 940531859 -734975579 -52198603 4131644 64569752 -873188920 580381882 -76953540 -384247421 -492977305 30349934 -50083193 -953931287 822158844 -664673696 254199470 -815681129 603989041 245097503 -32707666 371563603 591440772 94388507 -993950981 -194920155 146339257 248749264 -735925074 -39312110 924009523 894255379 -675501609 22187708 -157903604 -392365598 290439724 -203513528 808888742 491846161 -84993261 -501321498 489343704 651561822 821683349 -355406303 364445383 -766877236 988730359 -270894774 37226120 -773836055 -734227301 373559423 -894522072 -362735842 -356676406 914079560 …
Output: 56975303 -848964344 -801894430 -801894430 -512342231 -512342231 -109799345 -139128947 -139128947 -512342231 -139128947 -139128947 -119136935 -139128947 -139128947 -139128947 -119136935 -119136935 -109799345 -109799345 -29771462 -109799345 -52198603 -52198603 -29771462 -52198603 -29771462 -52198603 -52198603 -76953540 -52198603 -52198603 -52198603 -52198603 -52198603 -52198603 -52198603 -52198603 -50083193 -50083193 -32707666 -32707666 -29771462 -32707666 -32707666 -32707666 -29771462 -32707666 -32707666 -32707666 -29771462 -32707666 -29771462 -32707666 -32707666 -32707666 -32707666 -32707666 -29771462 -32707666 -32707666 -32707666 -29771462 -29771462 -29771462 -29771462 -29771462 -29771462 -29771462 -29771462 -29771462 -32707666 -29771462 -32707666 -32707666 -39312110 -32707666 -39312110 -…

Example 3:

Input: 1336 983582028 467604350 -40469731 68119160 -205279586 -330335259 -662011021 179206042 -430807489 971379906 -237611082 -592220434 474568977 -228215898 131332580 861582652 536607860 -839642846 477656463 195259410 -199405769 670118910 -435475725 -15978891 824164611 910718880 -776666455 -991520040 -428954575 -534526155 815956855 -250834443 -172933823 811935060 71485779 191023038 -391864058 87973055 74206602 -152261875 -16646623 -339392854 -811599204 702100578 110961314 269327724 -991386809 -767540890 -627407080 -186508281 935013992 434027683 -613263729 -568670935 -531860578 -297795012 77289243 -164729148 474712030 967693276 -268673099 -214189337 237111798 449041006 652644397 -358904567 -705230404 934478031 257163003 -394287975 -628689957 808919903 717565021 37809262 -481365651 743738591 40021…
Output: 983582028 467604350 467604350 68119160 68119160 -40469731 -40469731 -40469731 -40469731 -40469731 -40469731 -205279586 -40469731 -205279586 -40469731 -40469731 68119160 -40469731 68119160 68119160 68119160 68119160 68119160 -15978891 68119160 68119160 68119160 -15978891 -15978891 -40469731 -15978891 -40469731 -40469731 -40469731 -15978891 -15978891 -15978891 -15978891 68119160 -15978891 -15978891 -16646623 -16646623 -16646623 -15978891 -15978891 -15978891 -16646623 -16646623 -40469731 -16646623 -16646623 -16646623 -40469731 -40469731 -152261875 -40469731 -152261875 -40469731 -40469731 -40469731 -152261875 -40469731 -40469731 -16646623 -40469731 -40469731 -40469731 -16646623 -40469731 -40469731 -40469731 -16646623 -16646623 -16646623 -16646623 -15978891 -16646623 -16646623 -16646623 -159788…

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Ivo's ledgers Middle So Far - MEDIUM Coding Problem | CodeTikki