CT64662

Esha and the Middle So Far

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

Morning light hits the lotus ponds of Tranquil Basin as Esha unrolls the day's manifest of signals. 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: 369 -927502089 482066475 120143787 127318710 -548980566 721519137 -919059639 -976750438 -344110916 670895906 132673289 526587852 -540985280 536243457 101974555 -511086923 -277331994 -118542572 191409696 192762832 826226143 919566418 318931597 -881236511 -376891576 -24471652 845639279 439991455 -589364534 -784936722 792338051 -141002943 334930906 -355834292 188090077 590075782 870749276 861212339 -116737422 -782074467 -542888030 -69480198 921331136 893485346 -228602603 732118306 -248234111 801890150 -660810322 639343769 -328604110 4460596 699143904 649686141 746767967 254142713 460643594 467081529 -45601087 26651202 404671557 577674255 367222852 877145767 876101625 -100174071 23440469 -21741922 -759394923 400678694 766387283 872792125 536531794 -259462154 523600679 251533941 -907714744 -265…
Output: -927502089 -927502089 120143787 120143787 120143787 120143787 120143787 -548980566 -344110916 -344110916 120143787 120143787 120143787 120143787 120143787 101974555 101974555 -118542572 101974555 101974555 120143787 120143787 127318710 120143787 120143787 101974555 120143787 120143787 120143787 101974555 120143787 101974555 120143787 101974555 120143787 120143787 127318710 127318710 127318710 120143787 120143787 101974555 120143787 120143787 120143787 120143787 120143787 120143787 120143787 120143787 120143787 101974555 120143787 120143787 127318710 127318710 132673289 132673289 132673289 127318710 132673289 132673289 188090077 188090077 191409696 188090077 188090077 132673289 132673289 132673289 188090077 188090077 191409696 188090077 191409696 191409696 191409696 188090077 188090077 1880…

Example 2:

Input: 1728 -98746883 -607247804 617835475 111896961 -220592532 344678034 859968596 957885701 -197550730 176102369 20553732 393523336 179919841 608550890 611310081 -181791967 -558803999 793284495 577877666 -464502803 232850582 -920890154 484143615 677622905 -453545415 448058184 -110452171 403192783 -569196571 -571131168 578707887 787613540 -882496099 -940089752 -423400068 614451497 -315410800 143935095 -759208170 512678689 -301277805 -975589806 898045569 -533777682 517074654 844742217 833013229 827286721 -95608820 445378999 -845060127 743448106 -98294616 487150665 -296897232 279767284 290270291 549911731 344654790 825117775 -314296775 15365891 -678230336 330173860 722861297 145691901 -90326756 770706510 137752045 740645800 -917784091 974392029 -764797371 529490434 -368480229 -42987608 886059929 -…
Output: -98746883 -607247804 -98746883 -98746883 -98746883 -98746883 111896961 111896961 111896961 111896961 111896961 111896961 176102369 176102369 179919841 176102369 176102369 176102369 179919841 176102369 179919841 176102369 179919841 179919841 179919841 179919841 179919841 179919841 179919841 176102369 179919841 179919841 179919841 176102369 176102369 176102369 176102369 143935095 143935095 143935095 143935095 111896961 143935095 111896961 143935095 143935095 176102369 176102369 176102369 176102369 176102369 176102369 176102369 176102369 176102369 176102369 179919841 179919841 232850582 232850582 232850582 179919841 179919841 179919841 232850582 179919841 179919841 179919841 179919841 179919841 179919841 179919841 179919841 179919841 179919841 176102369 179919841 176102369 176102369 176102369…

Example 3:

Input: 845 -597915405 685271979 313344480 167385025 -990522944 -922993079 792837737 806971231 -748017419 -87781027 -938299860 -875617713 -102708932 -46358625 688175403 696676351 153519827 105550193 -720988200 -734411013 -453589575 -120226611 530112119 -585397894 -382247472 634625731 -15264200 -798252184 -115552090 556913415 -268784155 606606500 -745831436 -442816361 -505819391 -748032532 589228529 994072564 987267737 -285128448 817665641 -749108030 -534946670 -821555015 -139539044 577927697 -450164553 403207013 -161851561 971586540 -654630957 616796348 -845597024 447280311 -659062435 743130754 -606867497 779829108 508186593 -978391539 -551498142 -152119524 233581545 -751216500 -76189826 -448573806 -481627690 -356806095 686875215 -179873923 -468345692 495133467 441398941 -192764456 -414797675 7084…
Output: -597915405 -597915405 313344480 167385025 167385025 -597915405 167385025 167385025 167385025 -87781027 -87781027 -597915405 -102708932 -102708932 -87781027 -87781027 -46358625 -46358625 -46358625 -87781027 -87781027 -102708932 -87781027 -102708932 -102708932 -102708932 -87781027 -102708932 -102708932 -102708932 -102708932 -102708932 -102708932 -115552090 -115552090 -120226611 -115552090 -115552090 -102708932 -115552090 -102708932 -115552090 -115552090 -120226611 -120226611 -120226611 -120226611 -120226611 -120226611 -120226611 -120226611 -120226611 -120226611 -120226611 -120226611 -120226611 -120226611 -120226611 -115552090 -120226611 -120226611 -139539044 -120226611 -139539044 -120226611 -139539044 -139539044 -152119524 -139539044 -152119524 -152119524 -152119524 -139539044 -152119524 -15…

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Esha and the Middle So Far - MEDIUM Coding Problem | CodeTikki