CT65242

Smith's Bright scrolls

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

The tallyman Smith has been asked to plan the harvest festival. On the desk lies a long table of scrolls readings. 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 <= 2549; 0 <= a[i] <= 1000000000.

Example 1:

Input: 2321 509818124 577321534 940528485 737437654 964854788 269272916 359580731 740589841 478103796 822969341 50323991 961562040 882791080 704160273 506293892 387283815 562149081 944043995 673800682 774921018 667138022 352586352 880822985 419238995 714669285 310440335 161620922 584620299 480456885 950339300 788624773 327361473 992640410 312181763 528982213 286978439 24873641 644533326 361329463 252743024 981081189 849798980 57708481 950301077 231858992 793869468 263727916 791242058 369450589 561509448 818403159 788666440 153349899 367849093 236748152 67879899 10043471 437222429 189790465 51489136 946257831 129657111 667347114 485075750 712683170 646929015 395721261 961654598 423822606 712252219 459513545 105401051 461799852 27619482 635422743 224047383 646331616 469897096 906451028 502372348 16…
Output: 1143918352204

Example 2:

Input: 2074 348501647 579677096 721643988 634858755 332739379 52369408 256747991 223176716 407282185 15808505 80623686 226387836 515587228 155221467 219154113 884604331 523097774 558512571 679532460 728797885 73343917 297171382 531149620 772029353 52214348 18974748 198254181 904863294 47974930 796694725 472490318 866572149 538159843 735380279 197041596 300581429 494088274 272552711 174856893 265114832 529534609 769088541 122740743 414181443 134077004 477655535 756239469 294088394 593968759 118014748 46957065 145317951 100003946 231939418 965673202 668257942 867722616 309586454 760639307 379615984 488864793 985500098 463453706 38677678 180507241 798826079 429605866 338205970 175671997 592985315 688159692 254168580 634277691 210311429 617715873 694431698 572704007 290588941 164974658 554000624 5641…
Output: 1015197393214

Example 3:

Input: 2187 34369504 157902279 622421161 863800578 562627361 628854033 720514364 580171395 293548047 729912442 888452008 636949936 782329120 35767444 431082959 49763960 435433330 843720797 422155068 446768195 392135481 726816563 189424352 623181108 893248193 742892094 727718740 895096254 303290071 166707922 834399935 459656491 102685817 527026045 278261077 363116474 271685585 733174775 248413552 732092833 339652962 601819889 139957676 331453634 543962598 849730423 830238889 221232770 360330963 866345282 988421288 312264806 691273514 330662916 783117859 29778862 726531284 183216778 417562015 901865550 900733111 681817829 222677788 137708910 844392693 598957955 406979707 721750890 366725656 944881668 827182430 96577658 88987514 639561869 703667840 789879324 488134586 433172462 420267073 382650624 2…
Output: 1057396620281

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Smith's Bright scrolls - MEDIUM Coding Problem | CodeTikki