CT49322

The Rain Ledgers of the Scarlet segments

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

At the acacia flats of Thornveld, Envoy records each segments in a worn leather ledger. The guild wants answers, not guesses. Task: Heights a[i] form a skyline; after rain, water rests between higher bars. Print the total trapped water. Input format: First line: n. Second line: n nonnegative integers. Output format: Print the trapped water volume (fits 64-bit). Constraints: 1 <= n <= 2609; 0 <= a[i] <= 1000000000.

Example 1:

Input: 582 252308872 92233373 183116351 287578737 28484946 890952205 152739698 159396776 95010696 721884934 324101339 569200744 850424517 385335371 189913219 892854009 669652064 919849622 691643016 709897627 259341959 772956275 13665467 872272817 559209327 183555930 168733502 186560226 40629236 792509903 853051503 663913385 918983976 855584319 872777425 885069060 727512757 23588739 133172035 792275068 568559540 378355476 351602787 569513579 845541945 883595340 183905995 857316774 464722462 16411810 638630876 113165362 948395532 277136356 734867029 394448689 889196304 617962506 700466338 459057213 834082201 625547811 512816594 570929892 12693888 685569048 220442389 43595580 678790192 753971967 734272333 351244739 609619583 94780739 118939223 522819675 68960594 812133850 742070756 930105541 1483894…
Output: 269609484687

Example 2:

Input: 2338 840325808 212314051 652908408 766241749 732338871 830661029 267481364 786168809 513477719 557009352 256586794 834627758 148174111 57047824 553063241 828757244 370040296 510254898 219829731 837735672 780273405 484088198 339606700 71333549 243639275 813704850 957749636 617496055 193121259 705710248 871691408 483777796 625449562 934038597 9528517 330508769 262643696 386060313 194521560 554472518 985559260 712711481 578483416 167913457 173203061 566173885 983966377 523931200 911051140 991498127 755534066 244978273 873396734 301810180 116902915 102925813 796678624 23284698 196021113 454062291 317988989 845320675 777781917 125814961 215114335 414441720 518066772 420779715 743085263 575093663 140695082 624386862 140265647 710492057 915410036 310558320 899139084 262437547 250750096 782586292 …
Output: 1162856344534

Example 3:

Input: 1398 170868070 909899480 678061256 47264169 151839100 487156813 787411349 134301036 489793177 164614441 921106596 536455213 333661632 415929397 454545646 670636927 759443934 924417324 481874667 290773501 707628005 503354560 697186663 660079128 258135996 147708319 916269455 963274743 240160044 251235093 995083373 681540966 618499912 690334658 408986035 476949806 782499310 921195275 772140249 749186854 464214828 885209500 567599155 861263133 525287736 541285219 537925961 651363739 720938243 855761849 99236074 249730961 60169219 911609258 695787520 339005827 262839618 173563610 845151681 856363895 450733399 739909632 913614918 908010701 697209324 464508583 788715421 913629429 614776058 283664767 218663715 74504135 300921286 316436263 970970077 823675541 630534119 720424366 35236679 747943137 …
Output: 696207966169

Constraints:

1 <= n <= 2609; 0 <= a[i] <= 1000000000.

Loading...
Test Cases:No test cases
No test cases available.
The Rain Ledgers of the Scarlet segments - MEDIUM Coding Problem | CodeTikki