CT59346

Ivo's registers Middle So Far

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

Ivo runs the apiary at the boar woods of Tuskmore. Today the books show a list of registers, 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: 1888 -323596056 -480002787 321292561 829684197 777902439 -927767421 -229884734 -563461367 -555268175 -102130872 654495254 365119610 685658421 -438083227 911704623 -985050171 -669024391 506131033 601216500 826241753 -430814817 -568037377 -776768424 96037026 -307455767 -49172735 -367525822 924961874 -383297342 -412077500 693341560 -271503862 451589527 341884686 128255860 486207250 789433710 506533974 -435942423 -589488513 685149806 406304029 883006129 -367286782 81887197 -892046191 -348572967 843352755 -492806186 -39744473 337064568 -442487781 -764908884 730785177 320893420 -684055673 344153256 -605263428 35399360 -680960119 593999383 628931159 371428526 -357527964 -374825314 -664227925 55812708 -706695134 560884021 -488480972 -966320760 -27635846 -951239413 -718734715 768991207 813363275 -1…
Output: -323596056 -480002787 -323596056 -323596056 321292561 -323596056 -229884734 -323596056 -323596056 -323596056 -229884734 -229884734 -102130872 -229884734 -102130872 -229884734 -229884734 -229884734 -102130872 -102130872 -102130872 -229884734 -229884734 -229884734 -229884734 -229884734 -229884734 -229884734 -229884734 -307455767 -229884734 -271503862 -229884734 -229884734 -102130872 -102130872 -49172735 -49172735 -49172735 -102130872 -49172735 -49172735 96037026 -49172735 81887197 -49172735 -49172735 -49172735 -49172735 -49172735 -39744473 -49172735 -49172735 -49172735 -39744473 -49172735 -39744473 -49172735 -39744473 -49172735 -39744473 -39744473 35399360 -39744473 -39744473 -49172735 -39744473 -49172735 -39744473 -49172735 -49172735 -49172735 -49172735 -102130872 -49172735 -49172735 -49172…

Example 2:

Input: 2214 -463342416 959818359 -304457528 -219007483 -393799395 954610184 -803739250 -39500390 101080718 -159002448 -119291652 -430944417 -471603382 537662361 -942423222 -624616283 194180660 -873560997 297991382 469308227 -561045043 50779238 -842385782 763756107 295274929 -597166614 736948711 -231060032 290530525 313593931 -960897866 468076781 -140181373 -840615510 693797985 -961898150 -960801685 -140960620 -206729790 -341997018 -194889219 -96398791 -846970897 6976319 919257774 522465523 445497929 431981403 977404213 -336944734 -648393729 -236898673 762284368 -686825126 -591847655 -37960441 709653859 -905769916 -972715651 840478526 -211442427 313024720 833344492 -499998734 -593626094 627247749 -128214987 -984294134 255912967 -485932707 -642803824 -67629918 922551852 -378888867 -10282040 -494204…
Output: -463342416 -463342416 -304457528 -304457528 -304457528 -304457528 -304457528 -304457528 -219007483 -219007483 -159002448 -219007483 -219007483 -219007483 -219007483 -304457528 -219007483 -304457528 -219007483 -219007483 -219007483 -219007483 -219007483 -219007483 -159002448 -219007483 -159002448 -219007483 -159002448 -159002448 -159002448 -159002448 -140181373 -159002448 -140181373 -159002448 -159002448 -159002448 -159002448 -206729790 -194889219 -194889219 -194889219 -194889219 -159002448 -159002448 -140960620 -140960620 -140181373 -140960620 -140960620 -159002448 -140960620 -159002448 -159002448 -159002448 -140960620 -159002448 -159002448 -159002448 -159002448 -159002448 -140960620 -159002448 -159002448 -159002448 -140960620 -159002448 -140960620 -159002448 -159002448 -159002448 -1409606…

Example 3:

Input: 50 -299288490 336969785 152948603 258718862 -159163370 -497703676 772780794 -134964346 102293492 -564417676 53031793 742549727 323831071 -892521100 220898567 26965591 260252988 741870903 533566036 -520319268 -127669843 -27217244 -782380770 165223939 -110198296 -197886433 -653194088 716271452 174957958 -418286767 442626078 165496854 -147635929 368241078 855280267 -849868053 -598145723 -898447926 657886962 -514742226 78386521 -583705738 -503769052 -501265413 410417970 -681376253 237769466 696257397 41590159 728625836
Output: -299288490 -299288490 152948603 152948603 152948603 -159163370 152948603 -134964346 102293492 -134964346 53031793 53031793 102293492 53031793 102293492 53031793 102293492 102293492 152948603 102293492 102293492 53031793 53031793 53031793 53031793 26965591 26965591 26965591 53031793 26965591 53031793 53031793 53031793 53031793 102293492 53031793 53031793 26965591 53031793 26965591 53031793 26965591 26965591 -27217244 26965591 -27217244 26965591 26965591 41590159 41590159

Constraints:

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

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