CT58373

The Middle So Far of Coralcove

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

Cartwright inherited the stall at the island market of Coralcove along with its curious bookkeeping system for marks. Time to make sense of it. 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: 823 -462417578 246253342 711331004 947990827 -143799192 -48369370 871061220 -653249422 913912892 -919968535 -326694996 -950373512 565152783 812978157 350673789 -57809331 451711589 -374976773 787294024 -691327075 154537204 215226601 -440486075 -267639399 398082798 687594038 -84084039 -75271263 310841706 -517481847 -410513564 343452354 816539113 -954975463 860850084 310980318 -277422565 144527058 -447697620 -575869720 -258746601 -73162337 838816271 41118122 888875188 -410090136 -879231835 401733700 506653246 239697430 -478044010 51076110 722889924 -657723571 -835278627 -909391946 -271031796 -247132400 97600323 -216123917 -439798294 820092371 -650771217 -183380028 324882107 493619963 -934153678 -85185335 992396542 -160291166 -687621469 303181665 297961036 227553967 926941471 526847281 7682254…
Output: -462417578 -462417578 246253342 246253342 246253342 -48369370 246253342 -48369370 246253342 -48369370 -48369370 -143799192 -48369370 -48369370 246253342 -48369370 246253342 -48369370 246253342 -48369370 154537204 154537204 154537204 -48369370 154537204 154537204 154537204 -48369370 154537204 -48369370 -48369370 -48369370 154537204 -48369370 154537204 154537204 154537204 144527058 144527058 -48369370 -48369370 -57809331 -48369370 -48369370 41118122 -48369370 -48369370 -48369370 41118122 41118122 41118122 41118122 51076110 41118122 41118122 -48369370 -48369370 -57809331 -48369370 -57809331 -57809331 -57809331 -57809331 -73162337 -57809331 -57809331 -57809331 -73162337 -57809331 -73162337 -73162337 -73162337 -57809331 -57809331 -48369370 -48369370 7682254 7682254 7682254 -48369370 7682254 -48…

Example 2:

Input: 2285 -441377487 283811271 -274600984 -21642748 596007560 -640861497 75135871 -314924955 329715612 386443585 347435262 438314362 413730388 -944030455 403671586 -247706063 957417590 239172742 -766375377 -240591567 472743363 542379507 -682187568 209317596 -834491147 563937061 165214465 -209011219 -141096164 907828260 196610849 -109565202 763946222 -498194763 -252520706 270053541 452533105 -835418252 620421523 409665231 -323321288 -836453251 212502564 679846817 -158311876 -755944766 -876810595 698467482 662354079 -50214501 -926000433 -374499025 -554109202 681466935 -842306148 139031961 -865735927 936718410 -908136991 391084399 -118095866 729421495 956926701 -860716002 395235500 -388425567 131189739 -868701418 -122285828 -617661605 36593344 -542599134 -269481100 -355543359 -995287377 535731789 …
Output: -441377487 -441377487 -274600984 -274600984 -21642748 -274600984 -21642748 -274600984 -21642748 -21642748 75135871 75135871 283811271 75135871 283811271 75135871 283811271 239172742 239172742 75135871 239172742 239172742 239172742 209317596 209317596 209317596 209317596 165214465 165214465 165214465 196610849 165214465 196610849 165214465 165214465 165214465 196610849 165214465 196610849 196610849 196610849 165214465 196610849 196610849 196610849 165214465 165214465 165214465 196610849 165214465 165214465 75135871 75135871 75135871 75135871 75135871 75135871 75135871 75135871 75135871 75135871 75135871 139031961 75135871 139031961 75135871 131189739 75135871 75135871 -21642748 36593344 -21642748 -21642748 -50214501 -50214501 -50214501 -50214501 -109565202 -109565202 -113622139 -109565202 -…

Example 3:

Input: 740 -582212708 -798593082 567218729 761727547 -501092545 151533147 334395220 161154798 684517075 -601003359 -852622337 582768356 -805498039 -504680076 26701840 306409763 524412226 517517236 -452323096 -126262992 -589199076 844047865 -722146283 969866994 -435257713 -484386125 -641725230 119679463 -304632427 773201442 4996984 373532577 172486464 -147487802 -712501916 -233867906 -331011588 -359611112 734684829 -636973858 -399366012 -620526006 -147641362 987768980 256933804 -236993642 -371092769 -201408547 412167257 -723896249 -984170279 -735127238 383683062 833836227 -36140185 425807967 -114493127 36809480 298654421 -892902215 -739764001 440413924 -990128180 -742343872 459764784 108517098 -340968051 895024004 293989330 -432034876 -539887904 -256994569 -736234066 -956619689 877539781 421219489…
Output: -582212708 -798593082 -582212708 -582212708 -501092545 -501092545 151533147 151533147 161154798 151533147 151533147 151533147 151533147 -501092545 26701840 26701840 151533147 151533147 151533147 26701840 26701840 26701840 26701840 26701840 26701840 -126262992 -126262992 -126262992 -126262992 -126262992 4996984 4996984 26701840 4996984 4996984 -126262992 -126262992 -147487802 -126262992 -147487802 -147487802 -233867906 -147641362 -147641362 -147487802 -147641362 -147641362 -201408547 -147641362 -201408547 -201408547 -233867906 -201408547 -201408547 -147641362 -147641362 -147487802 -147487802 -126262992 -147487802 -147487802 -147487802 -147487802 -147641362 -147487802 -147487802 -147487802 -147487802 -126262992 -147487802 -147487802 -147641362 -147641362 -201408547 -147641362 -147641362 -147…

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 Coralcove - MEDIUM Coding Problem | CodeTikki