CT60130

Anaya's Middle So Far Ledger

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

Caravans arrive at the dune sea of Caravanrest with crates of beacons, and Anaya the store warden must account for every last one. 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: 2047 -703609881 529063609 167323770 -47763341 -927044974 -198356785 -752099742 732628372 572258131 -509050447 -411843904 -136017829 -660860822 -804694440 -904041595 451129833 -665565407 -714689117 -161065706 834360405 -14505899 -690868667 648531815 -975085788 856958432 322262271 51804077 -241977478 -7990208 597708169 -773774465 -68694847 754588742 827233911 926684210 201528144 825151774 -550843323 210717050 185319805 -597891341 75535602 -668011574 898444732 -95762909 458105802 -232129885 -124742902 832716664 -406822086 -112647367 73915976 -573141681 -891640998 -580709344 508105618 -856442521 -682630779 -847236971 634298764 486227464 -632893458 -280060399 -68741842 138695331 -216196590 475476223 -476807876 285177283 -928661256 -658666847 -527773927 -726576107 -366125994 925779174 101215191 …
Output: -703609881 -703609881 167323770 -47763341 -47763341 -198356785 -198356785 -198356785 -47763341 -198356785 -198356785 -198356785 -198356785 -411843904 -411843904 -411843904 -411843904 -509050447 -411843904 -411843904 -198356785 -411843904 -198356785 -411843904 -198356785 -198356785 -161065706 -198356785 -161065706 -161065706 -161065706 -161065706 -136017829 -136017829 -68694847 -68694847 -47763341 -68694847 -47763341 -47763341 -47763341 -47763341 -47763341 -47763341 -47763341 -47763341 -47763341 -68694847 -47763341 -68694847 -68694847 -68694847 -68694847 -95762909 -95762909 -95762909 -95762909 -112647367 -112647367 -112647367 -95762909 -112647367 -112647367 -112647367 -95762909 -112647367 -95762909 -112647367 -95762909 -112647367 -112647367 -124742902 -124742902 -136017829 -124742902 -12474…

Example 2:

Input: 1935 917904894 266012658 -951086881 118052683 -51337637 674869039 -908800862 963283863 281901496 -872223010 859258637 353426955 584653798 509514745 808882312 -146390740 -447395619 767732295 -47926326 723450568 657478139 -74131514 804948046 -723401672 -655236721 14502604 930577417 -362439678 -514314859 -136571267 -37720486 -707235857 712210774 96416578 -178020413 591999301 -738315129 -308095695 744277486 -919541617 -363735626 -56313509 344447985 -835888798 978497986 -153461482 397776257 505234910 168361257 -825699796 -770548627 -123075076 702353988 -306285001 -8737008 859090726 88255397 -663365957 913769617 36659337 -80747836 -402601900 -856244164 -300421781 523151859 -339264719 436386908 729067508 368942151 795999054 -183097147 557843146 -39488360 -792865301 308367785 195636817 -427614010 …
Output: 917904894 266012658 266012658 118052683 118052683 118052683 118052683 118052683 266012658 118052683 266012658 266012658 281901496 281901496 353426955 281901496 281901496 281901496 281901496 281901496 353426955 281901496 353426955 281901496 281901496 266012658 281901496 266012658 266012658 118052683 118052683 14502604 118052683 96416578 96416578 96416578 96416578 14502604 96416578 14502604 14502604 -37720486 14502604 -37720486 14502604 -37720486 14502604 14502604 96416578 14502604 14502604 -37720486 14502604 -37720486 -8737008 -8737008 14502604 -8737008 14502604 14502604 14502604 -8737008 -8737008 -37720486 -8737008 -37720486 -8737008 -8737008 14502604 14502604 14502604 14502604 14502604 -8737008 14502604 14502604 14502604 -8737008 14502604 14502604 14502604 -8737008 -8737008 -37720486 -377…

Example 3:

Input: 318 614866388 -379198586 -564044251 750231381 678523585 -412534923 694794833 756895857 330867069 394524279 452408506 -798734754 -565239088 487361840 378100573 -612817775 -425246367 -988184859 -936841676 897420564 -970328800 408222435 438969713 374984874 -475433288 173402547 503396481 659574535 -724326339 732959889 -150338983 682371438 -250409752 415498020 149070744 186136978 -869433739 -450747478 224548637 671348804 -438127519 -804172362 709805978 84039404 57099688 835232619 -900278638 184268188 -649694172 -890210900 877511819 -826425288 529163410 37217566 762554611 -954616431 -399135390 142427079 -683374741 384411227 88009522 364055927 516478145 -96172518 -26953511 -83762438 312066646 -609099781 -688655164 609492733 -723144305 656841040 696675196 -278763949 131248484 -362045442 809529435 …
Output: 614866388 -379198586 -379198586 -379198586 614866388 -379198586 614866388 614866388 614866388 394524279 452408506 394524279 394524279 394524279 394524279 378100573 378100573 330867069 330867069 330867069 330867069 330867069 378100573 374984874 374984874 330867069 374984874 374984874 374984874 374984874 374984874 374984874 374984874 374984874 374984874 330867069 330867069 186136978 224548637 224548637 224548637 186136978 224548637 186136978 186136978 186136978 186136978 184268188 184268188 173402547 184268188 173402547 184268188 173402547 184268188 173402547 173402547 149070744 149070744 149070744 149070744 149070744 173402547 149070744 149070744 142427079 149070744 142427079 142427079 142427079 142427079 142427079 149070744 142427079 142427079 131248484 142427079 131248484 131248484 880095…

Constraints:

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

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