CT62310

Tanya's Sunlit Ledger

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

Tanya inherited the exchange at the crystal caves of Luminar along with its curious bookkeeping system for signals. Time to make sense of it. 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: 3686 -577075107 -580295142 -855307598 -180234031 866935452 -691864031 -658386600 533980063 221238261 432896076 537639624 40113399 442946485 -897058762 185222047 -895331135 -303455101 -540709143 -887810014 94448481 2314706 336674576 879950003 -709319000 128673244 -567380050 -263832550 -92431538 -975594673 918129678 -294632521 317112146 176283175 -549463646 -504412434 -343580063 487645885 -283861520 -13732222 996638019 -495403664 780951626 -535241157 -755580963 -171431927 -926368825 -10601631 90408146 580213043 463425688 -72271464 -328720285 225828448 -276018026 -337810734 -994747561 221374318 -553011929 623507327 375289015 572151532 265576650 -778963467 -379243841 -691991849 774230501 902213383 -656045897 -54773895 688739090 301657231 -642913441 620172915 -846770247 33283518 428221538 93591…
Output: -577075107 -580295142 -580295142 -580295142 -577075107 -580295142 -580295142 -580295142 -577075107 -577075107 -180234031 -180234031 40113399 -180234031 40113399 -180234031 -180234031 -303455101 -303455101 -303455101 -180234031 -180234031 2314706 -180234031 2314706 -180234031 -180234031 -180234031 -180234031 -180234031 -180234031 -180234031 -92431538 -180234031 -180234031 -263832550 -180234031 -263832550 -180234031 -180234031 -180234031 -180234031 -180234031 -263832550 -180234031 -263832550 -180234031 -180234031 -171431927 -171431927 -92431538 -171431927 -92431538 -171431927 -171431927 -180234031 -171431927 -180234031 -171431927 -171431927 -92431538 -92431538 -92431538 -171431927 -171431927 -171431927 -92431538 -171431927 -92431538 -92431538 -72271464 -92431538 -72271464 -92431538 -72271464…

Example 2:

Input: 892 924679594 -73033273 -111282778 -415324571 520807559 264033376 -758312806 -71735552 795319521 -352414735 -473213973 803999215 85145543 750892946 -611157626 121565251 -155499809 926604133 -906586571 -470376772 659465388 -94838539 -145054782 760878952 -805730315 564997733 678696314 -827733143 -751718214 -943181339 769697636 -913579765 955446651 538242606 -386573972 -907390443 -608058917 -704480010 210237108 259927388 982374856 162794707 670385756 431805295 -407768381 -717892325 538149518 -764364910 487877537 -172296683 354188925 24137486 337285258 20868312 -351389329 -831117647 795894533 936028872 582845495 309538061 -802877768 149235663 840345417 -76870239 -995570414 374504187 159957486 314672289 452224124 -286357612 942014467 -573472485 -93427185 771284938 -653465188 57760358 -443324250…
Output: 924679594 -73033273 -73033273 -111282778 -73033273 -73033273 -73033273 -73033273 -71735552 -73033273 -73033273 -73033273 -71735552 -71735552 -71735552 -71735552 -71735552 -71735552 -71735552 -73033273 -71735552 -73033273 -73033273 -73033273 -73033273 -73033273 -71735552 -73033273 -73033273 -94838539 -73033273 -94838539 -73033273 -73033273 -73033273 -94838539 -94838539 -111282778 -94838539 -94838539 -73033273 -73033273 -71735552 -71735552 -71735552 -73033273 -71735552 -73033273 -71735552 -73033273 -71735552 -71735552 24137486 20868312 20868312 -71735552 20868312 20868312 24137486 24137486 24137486 24137486 85145543 24137486 24137486 24137486 85145543 85145543 121565251 85145543 121565251 85145543 85145543 85145543 85145543 57760358 57760358 57760358 57760358 24137486 24137486 24137486 51763…

Example 3:

Input: 2590 -479604170 -241981890 236772619 128637016 -142987185 -624602066 6929677 817451749 703948667 196563392 395445519 445994606 -145380280 -787268808 762017140 -518414240 71943224 -959123901 -445222374 -575127044 -30413445 495243485 914306669 -857093538 228293953 813341857 -513900269 637238629 -492094670 962038331 29828456 -104801347 972612482 -974737897 -474258684 -627669757 -306326741 452573953 -589001108 -8509386 -31379327 44168635 912376341 905240187 -48364485 940757234 531200548 -869564452 321304117 -219197877 -99639910 221937427 220109872 -245617991 -169373298 -926581563 327024898 836503565 -836174827 -806113909 -216967411 -202476487 -196289792 824863904 996626571 -781845290 181824113 904090676 373360700 -204564632 -162905651 -163991320 -123706040 560759040 -214732720 -775500319 -5823…
Output: -479604170 -479604170 -241981890 -241981890 -142987185 -241981890 -142987185 -142987185 6929677 6929677 128637016 128637016 128637016 6929677 128637016 6929677 71943224 6929677 6929677 -142987185 -30413445 -30413445 6929677 -30413445 6929677 6929677 6929677 6929677 6929677 6929677 29828456 6929677 29828456 6929677 6929677 -30413445 -30413445 -30413445 -30413445 -30413445 -30413445 -30413445 -8509386 -8509386 -8509386 -8509386 6929677 -8509386 6929677 -8509386 -8509386 -8509386 6929677 -8509386 -8509386 -30413445 -8509386 -8509386 -8509386 -30413445 -30413445 -31379327 -31379327 -31379327 -30413445 -31379327 -30413445 -30413445 -8509386 -30413445 -30413445 -31379327 -31379327 -31379327 -31379327 -48364485 -48364485 -48364485 -31379327 -31379327 -31379327 -31379327 -30413445 -31379327 -30413…

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Tanya's Sunlit Ledger - MEDIUM Coding Problem | CodeTikki