CT58732

The beacons at Prismhaven

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

Morning light hits the glass towers of Prismhaven as Bhavi unrolls the day's manifest of beacons. 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: 2450 -668398856 -334241230 792537601 -234583046 -737122826 871418792 -980070522 992524643 438958814 242930844 -353419828 -45082774 958493407 -613165344 -371309490 -944415664 -863196082 303226767 875840287 838869142 769468779 -714712588 -652924255 688215900 854965661 -492254805 691975957 799424891 895425654 639871346 618123903 892951643 685090517 -356939216 981540423 -337175195 134240952 556796196 -121868625 -951843881 575166946 -794909224 -252357402 -931824842 299216327 -665338215 -399552113 966905657 -889879162 -690263376 506182011 -205475941 803909196 -520004565 -56675229 -277223481 677375394 -864434106 -818527350 -176002735 -529314347 -422754794 -74843514 -426963950 -151419510 197439455 643976387 -515147065 -33421981 -471737032 -97963734 -334481934 983987941 -822711410 -10154011 3947528…
Output: -668398856 -668398856 -334241230 -334241230 -334241230 -334241230 -334241230 -334241230 -234583046 -234583046 -234583046 -234583046 -45082774 -234583046 -234583046 -334241230 -334241230 -334241230 -234583046 -234583046 -45082774 -234583046 -234583046 -234583046 -45082774 -234583046 -45082774 -45082774 242930844 242930844 303226767 303226767 438958814 303226767 438958814 303226767 303226767 303226767 303226767 242930844 303226767 242930844 242930844 134240952 242930844 134240952 134240952 134240952 134240952 -45082774 134240952 -45082774 134240952 -45082774 -45082774 -56675229 -45082774 -56675229 -56675229 -121868625 -121868625 -176002735 -121868625 -176002735 -151419510 -151419510 -121868625 -151419510 -121868625 -151419510 -121868625 -151419510 -121868625 -151419510 -121868625 -121868625 …

Example 2:

Input: 1899 -13555824 -741739048 -183099919 303327646 36482777 929186378 -959092049 -935698652 660305881 354134781 964390456 -38957154 810860176 -185434087 -976636866 -968102032 -664386062 827177709 134547606 -342492877 -884786151 715424221 870841239 -162184956 -470990972 -770679506 -739730830 496704372 823861287 -474527696 -349336054 577977156 993978844 -243304874 18016258 639211861 24893596 -82332654 637689650 -451850461 -186863463 -982569327 709099797 637089937 -738766124 662199540 -866405054 469407247 -497933548 -407382510 -12978879 895751275 -99431226 255068066 69925907 631358593 377045035 -195819751 -627735422 509365307 529685213 -65964514 -542740171 -370535192 572921753 -109105937 -195772595 -829042421 462448705 -434614585 -279135625 383283643 244206360 -974790380 234592123 975090673 64937…
Output: -13555824 -741739048 -183099919 -183099919 -13555824 -13555824 -13555824 -183099919 -13555824 -13555824 36482777 -13555824 36482777 -13555824 -13555824 -38957154 -38957154 -38957154 -13555824 -38957154 -38957154 -38957154 -13555824 -38957154 -38957154 -162184956 -162184956 -162184956 -38957154 -162184956 -162184956 -162184956 -38957154 -162184956 -38957154 -38957154 -13555824 -38957154 -13555824 -38957154 -38957154 -82332654 -38957154 -38957154 -38957154 -38957154 -38957154 -38957154 -38957154 -82332654 -38957154 -38957154 -38957154 -38957154 -13555824 -13555824 -12978879 -13555824 -13555824 -13555824 -12978879 -13555824 -13555824 -38957154 -13555824 -38957154 -38957154 -65964514 -38957154 -65964514 -65964514 -65964514 -38957154 -65964514 -38957154 -38957154 -13555824 -38957154 -13555824 -…

Example 3:

Input: 2099 -541648277 -232023535 171088140 -161016856 -707548784 497072557 -585226306 985471035 -351780518 -870458600 655356503 399059207 -41321917 -260388318 -698022581 955324712 -847451158 634304668 -686967413 -657526499 63622054 316097731 -391968487 508122809 981244226 624359919 -786835812 965085442 195028899 806084288 704944195 -254514446 121088404 30611049 591771751 127390329 -595622340 -415044388 257308397 673808910 871537971 501449638 -241202582 -398380305 -352617096 273350424 -241254086 -30685242 -787459648 -30747938 380013357 -680359170 -297818399 -86283323 201929468 -48728267 -241939719 699380898 729551117 398520782 -92853406 -520824813 161780055 -936134247 456974158 952548087 500454686 388529665 -444484771 151153171 587666886 -453047026 -88648115 949390256 -771529768 515070630 -288858…
Output: -541648277 -541648277 -232023535 -232023535 -232023535 -232023535 -232023535 -232023535 -232023535 -351780518 -232023535 -232023535 -161016856 -232023535 -232023535 -232023535 -232023535 -232023535 -232023535 -260388318 -232023535 -232023535 -232023535 -232023535 -161016856 -161016856 -161016856 -161016856 -41321917 -41321917 63622054 -41321917 63622054 30611049 63622054 63622054 63622054 30611049 63622054 63622054 121088404 121088404 121088404 63622054 63622054 63622054 63622054 30611049 30611049 -30685242 30611049 -30685242 -30685242 -30747938 -30685242 -30747938 -30747938 -30747938 -30685242 -30685242 -30685242 -30747938 -30685242 -30747938 -30685242 -30685242 30611049 30611049 30611049 30611049 63622054 30611049 30611049 30611049 30611049 30611049 30611049 -30685242 30611049 -30685242 …

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
The beacons at Prismhaven - MEDIUM Coding Problem | CodeTikki