CT64384

The Frosted Rain Ledgers

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

Legend says the vault under the archive halls of Scrollkeep opens only for a perfect tally of panels. Dante means to find out. 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 <= 1229; 0 <= a[i] <= 1000.

Example 1:

Input: 245 477 529 312 564 383 534 828 855 890 768 308 996 882 49 122 313 772 191 187 853 487 123 11 62 443 237 426 492 576 144 95 275 225 533 807 453 626 253 735 222 984 158 920 110 841 920 811 100 976 869 786 660 987 87 612 16 290 874 997 269 147 446 935 696 760 942 614 524 697 70 835 273 605 501 403 851 907 928 237 47 920 771 590 835 27 869 997 51 278 239 160 854 768 520 139 980 874 311 10 766 505 117 573 12 679 598 771 465 113 407 637 421 230 758 186 158 400 700 298 461 958 431 841 445 181 35 66 487 391 291 975 498 600 309 476 34 682 768 655 793 930 581 847 383 896 719 393 121 358 813 25 310 786 626 195 143 497 634 613 877 40 878 130 868 492 165 564 745 889 219 287 86 139 748 838 217 447 609 949 179 542 491 443 45 884 193 211 248 335 968 944 171 270 170 600 813 189 663 182 682 686 725 790 386…
Output: 112907

Example 2:

Input: 645 0 272 174 91 802 841 536 108 957 337 646 951 275 498 90 711 567 67 918 535 127 240 653 905 903 602 235 617 326 823 240 55 767 23 135 336 118 607 765 685 754 229 654 122 872 976 384 659 979 22 131 822 105 294 429 640 725 263 431 323 841 206 935 884 787 376 776 16 920 288 356 32 236 193 54 865 659 745 154 719 604 50 544 499 882 645 240 593 186 45 124 821 385 485 267 560 830 687 720 179 60 889 838 137 750 93 239 352 451 480 285 254 877 32 922 234 880 903 378 293 433 342 338 280 934 719 851 20 764 654 846 433 799 159 964 975 848 8 579 515 31 367 776 341 884 604 622 345 810 643 201 593 3 477 763 683 901 434 1 67 126 682 309 671 450 548 691 72 94 444 152 956 959 701 402 495 229 785 113 933 889 713 614 960 548 431 294 740 261 261 763 754 961 57 697 561 733 637 951 772 826 680 643 293 504 748 …
Output: 312733

Example 3:

Input: 852 167 561 194 839 320 868 710 129 241 949 353 905 719 515 950 143 386 616 58 236 901 542 674 686 249 449 487 104 989 123 581 129 314 70 102 809 651 638 154 25 789 344 350 374 497 55 129 940 781 516 977 44 747 11 43 378 557 671 958 578 990 743 916 242 900 310 321 289 15 134 919 396 716 633 906 501 739 24 386 865 753 202 447 434 301 469 510 139 688 225 901 807 861 887 864 691 127 296 943 324 22 112 726 224 233 781 669 110 89 742 720 158 3 521 293 874 669 700 474 510 607 328 231 30 502 481 261 457 617 191 785 644 72 473 605 755 52 835 338 703 41 197 701 958 371 885 695 151 967 311 233 815 209 248 39 371 647 287 237 154 496 123 151 484 78 263 216 63 428 942 544 581 394 135 312 616 994 478 412 365 872 893 546 215 762 644 639 132 541 886 235 161 749 622 510 146 532 36 948 851 640 910 26 939 27…
Output: 419187

Constraints:

1 <= n <= 1229; 0 <= a[i] <= 1000.

Loading...
Test Cases:No test cases
No test cases available.
The Frosted Rain Ledgers - MEDIUM Coding Problem | CodeTikki