CT62587

The Vermilion ledgers of Lakshya

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

Lakshya the bookkeeper watches over the mangrove channels of Rootwater's stores of ledgers. A careful computation stands between order and chaos. 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: 2959 -228899091 158240380 -220197290 -366394926 -885859987 -61999172 -862317178 -734760841 258683471 -215574552 238304296 -510414353 465368519 278497474 -378939301 691336279 406419217 -159212483 964181733 -317589365 868297418 -847518317 -480859952 -971925866 -204046980 -898347813 547770472 -533903239 352172139 738701214 -760761107 225457250 -707017950 935283924 109698923 -670029754 -926514078 622221775 -328144416 490242501 -631070688 843029971 -749399219 -132375457 187761392 679348953 471979101 955039216 -648380514 673306745 -983332021 689839736 -542806169 263640849 775686949 -341968335 576257402 43641605 578888880 -235788564 -533064991 -131591768 -388120673 234747019 -131839933 -831724937 668826112 -552078604 694262496 -111900153 -229514653 374681383 -439839209 21201492 345342676 60642331…
Output: -228899091 -228899091 -220197290 -228899091 -228899091 -228899091 -228899091 -366394926 -228899091 -228899091 -220197290 -228899091 -220197290 -220197290 -220197290 -220197290 -215574552 -215574552 -159212483 -215574552 -159212483 -215574552 -215574552 -220197290 -215574552 -220197290 -215574552 -220197290 -215574552 -215574552 -215574552 -215574552 -215574552 -215574552 -204046980 -215574552 -215574552 -215574552 -215574552 -215574552 -215574552 -215574552 -215574552 -215574552 -204046980 -204046980 -159212483 -159212483 -159212483 -159212483 -159212483 -159212483 -159212483 -159212483 -132375457 -159212483 -132375457 -132375457 -61999172 -132375457 -132375457 -132375457 -132375457 -132375457 -131839933 -132375457 -131839933 -132375457 -131839933 -131839933 -131839933 -131839933 -13183993…

Example 2:

Input: 956 -679711442 563445450 519679351 -612795757 -215602778 -464160792 590811198 -948584069 938807015 -114681135 222369542 79170543 -24229047 452244252 165915643 -128440372 -207806463 -855832931 645256612 427009298 -25716166 -307278311 -542788136 922148921 149993999 -589472749 548967011 575850671 907893263 971551288 854736015 741735525 880995424 -8403021 40304280 -653041322 86838749 171793759 -617432141 -2642826 -75033535 710366758 -963868517 -116893838 785723695 -201857552 852903080 -678948719 -887145201 980897526 530910853 -241300689 -717317632 -597515178 -691507983 -126549176 306452744 -106037017 -996231559 279079121 252278780 -448241822 274500072 -801417832 886628667 -995197020 -337050640 -812033506 574244210 97753375 595755184 -554786008 -224514102 937895244 706162251 262389356 879190127…
Output: -679711442 -679711442 519679351 -612795757 -215602778 -464160792 -215602778 -464160792 -215602778 -215602778 -114681135 -114681135 -24229047 -24229047 79170543 -24229047 -24229047 -114681135 -24229047 -24229047 -24229047 -25716166 -25716166 -25716166 -24229047 -25716166 -24229047 -24229047 79170543 79170543 149993999 149993999 165915643 149993999 149993999 79170543 86838749 86838749 86838749 79170543 79170543 79170543 79170543 40304280 79170543 40304280 79170543 40304280 40304280 40304280 79170543 40304280 40304280 -2642826 -2642826 -8403021 -2642826 -8403021 -8403021 -8403021 -2642826 -8403021 -2642826 -8403021 -2642826 -8403021 -8403021 -24229047 -8403021 -8403021 -2642826 -8403021 -8403021 -8403021 -2642826 -2642826 40304280 40304280 79170543 79170543 86838749 79170543 86838749 86838749…

Example 3:

Input: 1364 137255104 -229343786 -514206780 -25264817 6460350 31508206 -37986799 829014677 907393465 -822168521 193140647 601997226 -172067779 -463058356 -104764545 202346671 -745836127 -563565368 -528671414 -436468096 577577076 175995468 -549729418 -838737288 -706306201 34504974 619734991 309578290 942722721 483052200 679134235 133488671 -602084880 798641091 -642427820 -791461900 641982770 -219999574 56490472 -426014391 999740377 -993273891 478977282 -371140030 637068062 -356304864 -163168285 -568847328 187856975 -731736171 -701023008 -335561575 844403819 945489312 521757566 -36874104 333132645 -688688269 -381731366 -781405653 -664521109 516678066 247042569 -181523739 676720385 -227944976 -796730012 146719076 -180200846 -389521153 -299324996 965133564 -804568455 843256038 -948287407 -430671180 -…
Output: 137255104 -229343786 -229343786 -229343786 -25264817 -25264817 -25264817 -25264817 6460350 -25264817 6460350 6460350 6460350 -25264817 -25264817 -25264817 -25264817 -37986799 -37986799 -104764545 -37986799 -37986799 -37986799 -104764545 -104764545 -104764545 -37986799 -37986799 -25264817 -25264817 6460350 6460350 6460350 6460350 6460350 -25264817 6460350 -25264817 6460350 -25264817 6460350 -25264817 6460350 -25264817 6460350 -25264817 -25264817 -37986799 -25264817 -37986799 -37986799 -104764545 -37986799 -37986799 -25264817 -36874104 -25264817 -36874104 -36874104 -37986799 -37986799 -37986799 -36874104 -37986799 -36874104 -37986799 -37986799 -37986799 -37986799 -104764545 -104764545 -104764545 -104764545 -104764545 -104764545 -163168285 -163168285 -163168285 -104764545 -104764545 -72842807…

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
The Vermilion ledgers of Lakshya - MEDIUM Coding Problem | CodeTikki