CT57168

Chetan's Solar registers

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

Chetan runs the loom house at the garden city of Petalbrook. 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: 3127 -102491177 744352165 958178685 -583916336 311851628 345355365 -972879975 318355551 -135033571 -313970243 767885006 510615535 297946969 -609514813 -839686823 -611815614 -895741008 966588655 467622824 919961818 -613214401 754023039 711802318 822187249 361059262 858182376 569266037 59844778 -187063005 507495652 493049302 -783189971 -995442791 843994627 -864876292 156057494 850662537 -57067262 554432750 -844562525 -226845766 -684896960 315705932 -362399125 -525411609 -771126221 -923989266 -292636162 -43206049 -348054368 125416144 -439929990 -801139319 793296315 -587386745 224657552 -559251731 121658402 996768236 -776532261 -137646931 297352165 278091569 169626218 -297762673 -4476590 404898954 -29464849 347712478 -335609416 699400562 144813200 -446097543 -406415431 -539041815 700473340 -44…
Output: -102491177 -102491177 744352165 -102491177 311851628 311851628 311851628 311851628 311851628 -102491177 311851628 311851628 311851628 297946969 297946969 -102491177 -102491177 -102491177 297946969 297946969 297946969 297946969 311851628 311851628 318355551 318355551 345355365 318355551 318355551 318355551 345355365 318355551 318355551 318355551 318355551 311851628 318355551 311851628 318355551 311851628 311851628 297946969 311851628 297946969 297946969 156057494 156057494 59844778 59844778 -43206049 59844778 -43206049 -43206049 -43206049 -43206049 -43206049 -43206049 -43206049 59844778 -43206049 -43206049 -43206049 59844778 59844778 59844778 -4476590 59844778 -4476590 59844778 -4476590 59844778 59844778 59844778 -4476590 -4476590 -4476590 -4476590 -4476590 59844778 -4476590 59844778 598447…

Example 2:

Input: 2914 971498479 453576234 -154508639 385661891 -702049437 80367638 491399809 -959052665 -994888098 216053033 -611654270 -327926386 -62929088 -21278210 929644606 234735705 941323267 280296299 -638295355 891953975 746077966 740443987 -526437915 387302761 -695050188 801501919 -701787699 -275935790 981628424 -713338798 -857450342 734352331 146800864 -838231534 -115788665 230715402 470276435 -587612013 -886597484 431205535 -206095765 -564719119 363393872 -268852697 -507073431 -721209445 679052209 88118702 -995372355 440667742 671571645 -178451658 311332917 95630652 405642792 561400 -293132512 354133976 -52285167 -174468976 -613009470 -522969765 642958346 874584032 699415628 922071901 408750442 999953837 -174773529 575465699 290694668 404660594 -85643563 -697474955 -766157900 -120077740 -36055503…
Output: 971498479 453576234 453576234 385661891 385661891 80367638 385661891 80367638 80367638 80367638 80367638 -154508639 -62929088 -62929088 -21278210 -21278210 80367638 80367638 80367638 80367638 216053033 216053033 216053033 216053033 216053033 216053033 216053033 80367638 216053033 80367638 80367638 80367638 146800864 80367638 80367638 80367638 146800864 80367638 80367638 80367638 80367638 -21278210 80367638 -21278210 -21278210 -62929088 -21278210 -21278210 -21278210 -21278210 80367638 -21278210 80367638 80367638 88118702 80367638 80367638 80367638 80367638 561400 561400 -21278210 561400 561400 80367638 80367638 88118702 88118702 88118702 88118702 95630652 95630652 95630652 88118702 88118702 80367638 80367638 80367638 80367638 561400 80367638 80367638 88118702 80367638 80367638 80367638 8036…

Example 3:

Input: 2030 -136275408 330258038 96274717 -149377406 -329985891 521740755 -613533327 -868884677 -808866483 349347239 -262807187 229456092 -177989051 910977685 491048173 -532584380 337241469 -179665819 -304075833 156847629 149542961 -381858987 -448728757 573801429 496361081 -611475614 -832461162 -7214729 -191644557 -687824934 -956900965 -851817465 -486726707 -977794298 266695910 -379181353 -718790892 458044693 884692349 988256038 175123577 -610716252 530172480 376106858 -68793224 716467937 -499042057 505379681 -7523367 -432089071 385541004 370750039 485791471 845880987 -410142405 204901023 349204469 411941649 -634688131 106738673 -767263840 848719019 -228392251 992790204 -573330309 591449196 -19944630 -287538894 -165697429 -884604372 180954648 593462212 621929938 -624961843 125428637 -649129688 68…
Output: -136275408 -136275408 96274717 -136275408 -136275408 -136275408 -136275408 -149377406 -149377406 -149377406 -149377406 -149377406 -149377406 -149377406 -136275408 -149377406 -136275408 -149377406 -149377406 -149377406 -136275408 -149377406 -149377406 -149377406 -136275408 -149377406 -149377406 -149377406 -149377406 -177989051 -177989051 -179665819 -179665819 -191644557 -179665819 -191644557 -191644557 -191644557 -179665819 -179665819 -177989051 -179665819 -177989051 -177989051 -149377406 -149377406 -149377406 -149377406 -136275408 -149377406 -136275408 -136275408 -68793224 -68793224 -68793224 -68793224 -7523367 -7523367 -7523367 -7523367 -7523367 -7523367 -7523367 -7523367 -7523367 -7523367 -7523367 -19944630 -19944630 -68793224 -19944630 -19944630 -7523367 -19944630 -7523367 -19944630 -75…

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Chetan's Solar registers - MEDIUM Coding Problem | CodeTikki