CT49245

The Glowfen Rain Ledgers

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Dev inherited the apothecary at the lantern district of Glowfen along with its curious bookkeeping system for scrolls. Time to make sense of it. 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 <= 3305; 0 <= a[i] <= 1000.

Example 1:

Input: 369 7 514 648 451 719 991 551 657 2 598 334 847 593 801 523 789 814 367 599 637 630 47 289 714 252 426 973 371 20 561 639 133 594 446 547 522 573 688 188 421 197 711 869 826 166 320 53 301 54 182 35 381 337 90 414 233 125 62 840 440 790 194 564 606 294 851 118 714 556 177 699 78 863 679 377 682 639 892 497 968 734 667 104 342 365 463 115 350 953 910 849 285 695 968 432 633 689 65 929 272 856 219 185 88 142 600 606 375 820 653 335 624 390 34 377 832 989 272 511 305 348 347 962 551 356 836 91 206 712 828 121 123 855 798 770 470 197 558 89 433 780 500 957 394 782 404 761 665 65 343 897 276 338 916 515 311 113 211 974 8 535 604 958 358 426 8 231 480 823 922 282 965 790 167 145 206 832 511 846 308 653 405 183 684 596 205 29 824 659 156 444 135 352 287 871 115 951 582 683 342 433 301 282 398 781…
Output: 175746

Example 2:

Input: 1974 413 713 64 921 457 889 656 407 823 646 439 10 682 246 420 495 10 91 593 101 588 983 442 138 410 999 243 671 341 484 941 577 699 993 667 798 987 537 507 838 381 74 75 252 294 959 60 564 287 515 677 39 891 737 744 93 255 114 689 22 177 282 557 309 291 219 600 66 172 830 491 636 698 2 520 623 215 44 197 397 331 376 183 359 187 720 620 282 813 740 430 611 663 354 397 873 603 94 462 444 315 404 897 253 429 364 790 983 46 565 779 130 497 503 712 461 618 62 872 973 586 519 137 442 845 695 770 115 280 226 885 7 402 49 60 60 842 582 812 608 690 340 111 652 843 954 513 40 938 59 3 807 501 451 0 710 724 243 79 238 227 229 957 716 988 729 779 683 396 216 487 342 947 795 298 745 877 207 867 174 74 985 769 491 194 821 347 25 514 517 975 499 24 972 921 549 349 683 419 118 433 82 640 683 879 291 595 …
Output: 986708

Example 3:

Input: 1940 630 600 425 600 979 514 74 635 276 646 702 904 254 702 220 399 355 543 206 999 358 220 41 422 363 873 615 444 135 177 80 70 938 631 502 73 967 142 957 844 803 515 624 598 66 108 533 277 318 302 966 1000 69 945 364 362 411 24 820 399 758 933 503 153 80 144 665 439 779 882 780 124 904 23 408 335 553 185 620 697 865 626 215 341 15 346 655 339 168 141 229 860 882 854 330 928 848 216 448 380 999 884 246 269 342 915 199 541 937 650 896 427 501 617 893 189 377 625 899 305 909 779 208 693 851 36 757 237 891 556 481 46 207 571 872 484 96 877 870 867 780 349 89 99 761 165 662 188 345 298 995 394 20 108 899 429 163 645 475 397 460 906 681 376 760 377 777 768 517 0 729 747 159 331 122 692 646 900 827 169 427 59 757 276 39 261 499 26 688 920 745 254 878 3 68 974 662 757 595 840 395 574 140 503 265…
Output: 979865

Constraints:

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

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