CT60818

The Middle So Far at Hammerfall

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

Deep in the anvil district of Hammerfall, Quill studies rows of signals entries. One clean number will settle the guild's oldest argument. 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: 873 -79350530 -594842031 -399878601 968472671 751494606 -516329300 -206369007 265019783 218449406 -47102923 -774567728 -411858059 611290404 -342283951 -839240673 -263955765 -859173412 455535235 874411086 486832101 -374861940 463377758 -725240419 419826501 72703467 874903590 453900411 -852281931 138383840 -449147622 -94428550 107465592 -995853225 86494688 627264606 993534852 314295168 -864596732 -63260662 435145822 -230744687 86356114 -726701704 -510275818 58189192 800237637 371182541 -933593680 -69298814 -419481421 -134540439 503929910 -64505209 -723449386 751984796 660006569 -350474731 198553701 -364682821 673840405 645421333 -402107108 424071619 -267267131 -821636842 549427275 634493489 -581783775 921925356 -639619785 -517699898 466759136 350354642 227124962 -224306602 778787638 -8240352…
Output: -79350530 -594842031 -399878601 -399878601 -79350530 -399878601 -206369007 -206369007 -79350530 -79350530 -79350530 -206369007 -79350530 -206369007 -206369007 -263955765 -263955765 -263955765 -206369007 -206369007 -206369007 -206369007 -206369007 -206369007 -79350530 -79350530 -47102923 -79350530 -47102923 -79350530 -79350530 -79350530 -79350530 -79350530 -47102923 -47102923 72703467 -47102923 -47102923 -47102923 -47102923 -47102923 -47102923 -63260662 -47102923 -47102923 58189192 -47102923 -47102923 -63260662 -63260662 -63260662 -63260662 -64505209 -63260662 -63260662 -63260662 -63260662 -63260662 -63260662 -47102923 -63260662 -47102923 -63260662 -63260662 -63260662 -47102923 -63260662 -47102923 -63260662 -63260662 -63260662 -47102923 -47102923 -47102923 -47102923 -47102923 -63260662 -471…

Example 2:

Input: 3005 845111748 699835963 -746277598 415953234 827211023 924871348 -690989394 575954493 -752999769 -16375187 314356130 994483037 -730213011 297885467 -156688535 265596873 -371259213 701534504 433404253 -525308553 389058230 -876016878 -146505991 -446587070 -583096081 -98463685 823342185 459957068 -720161208 41976532 357847373 435150362 -7697978 88174713 983013343 -115166175 -190598583 -351469376 -234881459 737137719 647835025 795510277 -55865231 321391455 946024151 295994281 -640661533 154721852 670448944 255616076 -945300157 -477211360 898846308 -356039423 -993071896 -401011026 -783890107 -155903614 305172682 -73599961 274014330 -219917702 -752493678 366593994 22663421 493464777 209826721 -853515512 -386621469 -7079613 -659364931 -633165929 -635703839 -343328215 -525710375 226408335 4058968…
Output: 845111748 699835963 699835963 415953234 699835963 699835963 699835963 575954493 575954493 415953234 415953234 415953234 415953234 314356130 314356130 297885467 297885467 297885467 314356130 297885467 314356130 297885467 297885467 265596873 265596873 -16375187 265596873 265596873 265596873 41976532 265596873 265596873 265596873 88174713 265596873 88174713 88174713 41976532 41976532 41976532 88174713 88174713 88174713 88174713 265596873 265596873 265596873 154721852 265596873 255616076 255616076 154721852 255616076 154721852 154721852 88174713 88174713 41976532 88174713 41976532 88174713 41976532 41976532 41976532 41976532 41976532 88174713 41976532 41976532 22663421 22663421 -7079613 -7079613 -7697978 -7697978 -7697978 -7079613 -7079613 -7079613 -7079613 -7079613 -7697978 -7079613 -7697978 …

Example 3:

Input: 2074 553485580 -466832122 -421229584 -44730308 210317961 -468365425 874676897 -651415795 -362971451 947932892 -529610912 927778808 -27433544 -121514432 -785549837 949074657 -519648789 813715411 -927832308 205864382 406040681 565486211 -170178219 -903648419 591184642 232262091 -360108589 -854177607 -543813720 70839581 -481473956 -317655936 -325901667 620519518 624218406 868798572 210550527 968070611 897416107 999344928 -762253291 -843418484 697421546 -202609219 285738974 784730074 278833171 240756946 473770932 -361084121 182115793 856929038 799692902 -850297642 -776385022 198103267 -338334376 850962947 986035064 -269683128 348609642 176997021 -269451210 859933956 61984827 -320648676 340359888 -602097018 -21979996 854476875 89275194 -855203782 421809831 907923762 701318669 14302213 446857274…
Output: 553485580 -466832122 -421229584 -421229584 -44730308 -421229584 -44730308 -421229584 -362971451 -362971451 -362971451 -362971451 -44730308 -121514432 -121514432 -121514432 -121514432 -121514432 -121514432 -121514432 -44730308 -44730308 -44730308 -121514432 -44730308 -44730308 -44730308 -121514432 -121514432 -121514432 -121514432 -170178219 -170178219 -170178219 -121514432 -121514432 -44730308 -44730308 -27433544 -27433544 -27433544 -44730308 -27433544 -44730308 -27433544 -27433544 70839581 70839581 205864382 70839581 182115793 182115793 205864382 182115793 182115793 182115793 182115793 182115793 198103267 182115793 198103267 182115793 182115793 182115793 182115793 176997021 182115793 176997021 176997021 176997021 176997021 89275194 176997021 176997021 182115793 176997021 182115793 18211579…

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
The Middle So Far at Hammerfall - MEDIUM Coding Problem | CodeTikki