CT60269

Yuri's Ledger of ledgers

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

Yuri runs the mill at the anvil district of Hammerfall. Today the books show a list of ledgers, and the numbers must be worked out before sundown. 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: 2457 -699939161 -816490867 523035678 -586957483 -323978501 -406333455 7972639 -303131077 -373883063 569927540 -940182369 565249388 283193081 -921255480 -231930746 577506960 -453269594 -376468349 587898216 -196859029 -37440513 432814840 942783267 -166582150 -206783314 -92913110 -838244453 -617342186 476363305 -892294285 -720956887 -519013200 -123687982 956985759 871966662 -871020742 -926457896 -759045266 -287113401 -759234927 492407321 -486376791 -442708677 -6106010 488322445 -798622027 -578533210 164333925 -930728249 504794224 -897759759 278854435 433066208 -567224668 -613156027 443894998 519937262 478653399 319079357 340501773 -703278138 -934877077 -733503699 -221159306 -32298381 -733865745 -438848934 -625488013 628369577 305920847 -311040362 503786554 -91991378 -726779245 207373040 -3492…
Output: -699939161 -816490867 -699939161 -699939161 -586957483 -586957483 -406333455 -406333455 -373883063 -373883063 -373883063 -373883063 -323978501 -373883063 -323978501 -323978501 -323978501 -373883063 -323978501 -323978501 -303131077 -303131077 -231930746 -231930746 -206783314 -206783314 -206783314 -231930746 -206783314 -231930746 -231930746 -303131077 -231930746 -231930746 -206783314 -231930746 -231930746 -303131077 -287113401 -303131077 -287113401 -303131077 -303131077 -303131077 -287113401 -303131077 -303131077 -303131077 -303131077 -303131077 -303131077 -303131077 -287113401 -303131077 -303131077 -303131077 -287113401 -287113401 -231930746 -231930746 -231930746 -287113401 -287113401 -287113401 -231930746 -287113401 -287113401 -303131077 -287113401 -287113401 -287113401 -287113401 -2319307…

Example 2:

Input: 1690 -904670831 445797735 -332388703 787359653 -115395266 506732468 240459841 995429350 867450365 756119256 90637786 -307837636 328822519 -445955823 -144512281 990559714 -901841275 611362311 -141809453 336348060 -2633044 532984292 887331739 31438196 152124527 -860299594 878756402 -751085646 58363889 895380907 814217117 18804033 -585037184 922909317 -633045188 -818900573 -992949462 507485871 -661968760 165307479 -138603440 857521120 -15573480 -784126809 -424289935 -892141239 -384909934 -341664299 -799363670 438453307 521366322 698423656 202600634 -559295136 -451000354 -300369863 -257440300 -236489949 508248105 -10603278 -405694517 -926140888 -584751747 -37925000 -966926042 -231805762 724751976 -506525737 42548432 -533358981 -106204805 -309044923 -967384386 490526419 524135902 841599686 -377…
Output: -904670831 -904670831 -332388703 -332388703 -115395266 -115395266 240459841 240459841 445797735 445797735 445797735 240459841 328822519 240459841 240459841 240459841 240459841 240459841 240459841 240459841 240459841 240459841 328822519 240459841 240459841 152124527 240459841 152124527 152124527 152124527 240459841 152124527 152124527 152124527 152124527 90637786 90637786 90637786 90637786 90637786 90637786 90637786 90637786 58363889 58363889 31438196 31438196 18804033 18804033 18804033 31438196 31438196 58363889 31438196 31438196 18804033 18804033 -2633044 18804033 -2633044 -2633044 -10603278 -10603278 -15573480 -15573480 -37925000 -15573480 -37925000 -15573480 -37925000 -37925000 -106204805 -106204805 -106204805 -37925000 -37925000 -37925000 -37925000 -37925000 -37925000 -29013016 -290130…

Example 3:

Input: 2298 859304668 480753034 656149157 744789961 348304731 139766745 -847219439 400292703 958490388 -944878521 -301388178 -202635652 312297381 -154577739 -993848466 -538490740 -231501711 -243462134 -829734708 -722387800 -215654583 -755017795 -681949183 -260953645 845787206 660809690 -477975696 191916228 958657589 5410443 -201945164 930355809 -378775738 609918987 561531980 784919096 -839925291 575724879 -8068598 293752089 -386515409 -913154462 -867060816 -59212191 -210813686 456594711 -906348146 752198366 907614589 -356064500 706408546 -711254252 909644735 -736071498 398663890 -882666403 767713870 -249927393 -987693348 -204721601 414368290 -695956603 5271697 -472496357 718399633 -743186979 975146826 500594967 464325957 -781165671 -653540622 -741079865 -992711222 -873869713 -874572252 -82838453 …
Output: 859304668 480753034 656149157 656149157 656149157 480753034 480753034 400292703 480753034 400292703 400292703 348304731 348304731 312297381 312297381 139766745 139766745 -154577739 -154577739 -202635652 -202635652 -215654583 -215654583 -231501711 -215654583 -215654583 -215654583 -215654583 -202635652 -202635652 -201945164 -201945164 -201945164 -201945164 -154577739 -154577739 -154577739 -154577739 -8068598 -8068598 -8068598 -154577739 -154577739 -154577739 -154577739 -154577739 -154577739 -154577739 -59212191 -154577739 -59212191 -154577739 -59212191 -154577739 -59212191 -154577739 -59212191 -154577739 -154577739 -201945164 -154577739 -201945164 -154577739 -201945164 -154577739 -201945164 -154577739 -154577739 -59212191 -154577739 -154577739 -201945164 -201945164 -202635652 -202635652 -202…

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Yuri's Ledger of ledgers - MEDIUM Coding Problem | CodeTikki