CT61739

The Middle So Far of the Secret ledgers

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

In the herring shoals of Silverfin, Chavi the quartermaster keeps careful count of the ledgers. Map a faster supply route, every figure matters. 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: 2802 572308812 -846093041 -933371104 724147384 469289744 -575209575 -235272090 375290516 -701807766 588809329 -485938861 582069101 378705169 -195177474 668596774 -480502768 -804189655 -786238111 23844287 -924842650 515367076 267179307 985356698 -35335263 -134301617 -450683807 -75101130 71475734 -440370133 -945257991 -222418705 -932667682 127298070 339005073 -791532578 243594127 -839696376 492286855 898822387 121196225 -853265191 -674305611 -656698349 152143985 758707301 951466593 174210127 -989481758 -231064983 51216596 -874443494 155002097 426060366 -249627727 913598213 -768931766 942297768 485965737 -850125839 569482538 -536439882 856918991 -941419822 -510706440 316278261 642754050 54688173 442866719 -840117639 443980444 -655519247 -107095403 -139230927 -58934900 -524444368 -797306155 -3…
Output: 572308812 -846093041 -846093041 -846093041 469289744 -575209575 -235272090 -235272090 -235272090 -235272090 -235272090 -235272090 375290516 -195177474 375290516 -195177474 -195177474 -235272090 -195177474 -235272090 -195177474 -195177474 23844287 -35335263 -35335263 -134301617 -75101130 -75101130 -75101130 -134301617 -134301617 -195177474 -134301617 -134301617 -134301617 -134301617 -134301617 -134301617 -75101130 -75101130 -75101130 -134301617 -134301617 -134301617 -75101130 -75101130 -35335263 -75101130 -75101130 -75101130 -75101130 -75101130 -35335263 -75101130 -35335263 -75101130 -35335263 -35335263 -35335263 -35335263 -35335263 -35335263 -35335263 -75101130 -35335263 -35335263 23844287 23844287 23844287 23844287 23844287 -35335263 -35335263 -58934900 -58934900 -75101130 -75101130 -1070…

Example 2:

Input: 527 924479292 -993975656 73290448 -194082066 -941079998 -771623722 566031574 992841281 -105632395 27044938 482388471 -781019524 -628558548 -205705398 -92502986 -480313944 764682347 -598025737 -262342073 -791660863 -639422612 -102169873 -80205053 -653285714 -369778052 -474767910 -661757594 -382757807 347598168 167549974 -863397437 -524529902 183479009 -472181993 550194777 263256119 -831409612 -640618009 549354170 532980252 -205075449 20395933 -40862849 -840750183 -305578419 524943276 -642867012 -776239861 354078490 246023913 -354700563 964090047 27473837 276873003 960148310 -205526851 -949833289 287025141 158311293 -733887989 -926748930 -563122620 -566368045 -891123484 -779366596 -498684831 -464600699 -778734730 -695210686 -750409270 -526725396 188447182 580265248 -555709965 -333397121 9916…
Output: 924479292 -993975656 73290448 -194082066 -194082066 -771623722 -194082066 -194082066 -105632395 -105632395 27044938 -105632395 -105632395 -194082066 -105632395 -194082066 -105632395 -194082066 -194082066 -205705398 -205705398 -205705398 -194082066 -205705398 -205705398 -262342073 -262342073 -369778052 -262342073 -262342073 -262342073 -369778052 -262342073 -369778052 -262342073 -262342073 -262342073 -369778052 -262342073 -262342073 -205705398 -205705398 -205075449 -205705398 -205705398 -205705398 -205705398 -262342073 -205705398 -205705398 -205705398 -205705398 -205075449 -205075449 -194082066 -205075449 -205075449 -205075449 -194082066 -205075449 -205075449 -205526851 -205526851 -205705398 -205705398 -262342073 -262342073 -305578419 -305578419 -354700563 -354700563 -354700563 -305578419 -3…

Example 3:

Input: 3116 764365205 -419073807 -948501767 208948553 936380397 469572968 -78980585 -799138201 114858784 -454688834 603657108 -800714270 -401010776 -378234771 128460269 -740617724 517264388 245289606 -106219258 984774034 988165060 590066413 496427615 450632446 994413426 -754697578 -662905824 456496306 -270382950 121812206 -214210750 -874429277 908727891 605860610 566537055 -617238851 -55921147 -586646415 926345113 -288682951 153836643 -110967383 606495771 -955633921 -545779854 -64835351 64550005 -728333741 244018704 963311712 41510045 172671547 -473302802 -980950223 -348297612 -566588101 322460985 -851852626 470607328 801004805 -757576763 -124868558 -682692847 654684546 -836310792 -201788414 813141968 798806685 -962103645 846596238 -945289584 -154976403 335483786 994884514 105452590 -643752230 21…
Output: 764365205 -419073807 -419073807 -419073807 208948553 208948553 208948553 -78980585 114858784 -78980585 114858784 -78980585 -78980585 -378234771 -78980585 -378234771 -78980585 -78980585 -78980585 -78980585 114858784 114858784 128460269 128460269 208948553 128460269 128460269 128460269 128460269 121812206 121812206 114858784 121812206 121812206 128460269 121812206 121812206 114858784 121812206 114858784 121812206 114858784 121812206 114858784 114858784 -55921147 64550005 -55921147 64550005 64550005 64550005 64550005 64550005 41510045 41510045 -55921147 41510045 -55921147 41510045 41510045 41510045 -55921147 -55921147 -55921147 -55921147 -64835351 -55921147 -55921147 -55921147 -55921147 -55921147 -64835351 -55921147 -55921147 41510045 -55921147 41510045 41510045 64550005 64550005 105452590 64…

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
The Middle So Far of the Secret ledgers - MEDIUM Coding Problem | CodeTikki