CT43310

The Whispering Rain Ledgers

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Deep in the bamboo terraces of Verdantstep, Dora studies rows of stretches entries. One clean number will settle the guild's oldest argument. 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 <= 2802; 0 <= a[i] <= 1000000.

Example 1:

Input: 949 526274 483574 875563 928051 300744 198243 144438 571890 670977 517900 681284 284355 8621 399438 156930 866635 577424 650225 972879 953401 553814 663100 108822 16920 967110 270309 154740 543392 568715 333278 525323 906023 67099 999174 320853 987547 40664 769310 881466 181181 71668 944558 648535 222874 928230 436596 480964 824237 724940 546495 591650 682422 447459 842677 941419 849751 167108 328597 494111 337330 809139 402315 426480 607946 173309 130189 513233 947291 270297 616672 428220 793934 139107 349397 883534 77804 207059 394867 544574 789577 52942 788608 267011 635352 502382 122482 809622 255081 155876 31258 709841 950533 632154 673858 890610 349751 169416 109075 610104 172387 545821 113947 776910 743560 642179 334035 129676 643091 276671 711194 143394 132833 944661 282468 381277 …
Output: 467648937

Example 2:

Input: 543 564407 829287 330658 216965 886985 855674 918565 435249 329529 482061 97521 772932 632838 287056 772503 578603 361015 372282 608561 652103 288432 342166 361124 538949 694122 554381 764946 731622 941182 541221 201458 23948 547276 411292 449444 231538 995963 156045 825620 399292 44144 801021 107641 721044 851379 739392 749424 289650 808854 645248 429510 134822 707198 876414 384369 767359 950502 282959 307074 129610 983042 187320 756101 590320 709037 391920 474155 492583 641874 705468 500313 297289 774333 916317 844580 470829 613950 243105 250054 694594 758086 185774 588104 592889 336266 418983 992863 316233 531053 688891 960560 747888 461470 929861 589859 700560 362397 290765 712826 630505 560871 627246 954976 879656 843208 905119 246069 577419 739049 30301 238487 735835 978457 8692 1316…
Output: 257432052

Example 3:

Input: 2291 73696 927153 989513 237453 935836 848980 835078 89883 184853 543171 438101 890524 70711 957329 767317 613835 77224 387981 579252 483935 830605 460369 164700 471033 464069 428125 554776 77002 327418 335687 511478 135338 511362 188613 199592 999898 314864 57057 162576 840575 296021 15451 516106 680559 802998 547714 89301 907351 547848 344794 698326 510465 139850 848641 298207 18020 101616 514079 539896 336103 577364 255800 296157 372350 130531 901405 486993 123131 913249 707126 546458 231628 249334 32528 910988 560946 382032 788748 610730 519695 990119 149364 496033 925402 173916 174743 511280 319867 317359 677831 59351 115372 740256 9018 897841 869920 753424 193290 141806 118554 915057 454237 63759 162159 807070 165400 474537 701523 423971 266970 347915 638376 217228 171896 113482 4699…
Output: 1138373596

Constraints:

1 <= n <= 2802; 0 <= a[i] <= 1000000.

Loading...
Test Cases:No test cases
No test cases available.