CT61545

Sahil's Rain Ledgers Ledger

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

The customs officer Sahil has been asked to prepare the winter inventory. 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 <= 2389; 0 <= a[i] <= 1000.

Example 1:

Input: 1772 961 744 849 909 194 217 258 119 528 166 150 218 967 498 390 323 949 43 939 937 645 444 202 5 549 243 406 265 729 743 826 1 274 323 929 465 197 394 327 133 220 273 679 762 25 873 185 411 57 938 977 564 24 784 770 339 96 67 48 852 319 758 96 74 348 590 303 394 984 758 387 107 682 987 787 6 405 515 344 953 255 84 924 45 681 530 332 991 739 882 398 195 445 115 276 818 372 560 445 106 259 274 839 41 677 204 575 99 593 72 841 479 691 319 935 63 546 25 923 468 571 3 848 747 857 12 485 215 231 326 165 557 519 360 28 704 677 81 11 502 260 226 159 359 624 801 460 826 82 343 138 138 256 612 562 618 843 859 426 359 719 906 478 277 297 617 691 623 167 752 673 983 5 916 186 590 530 800 348 49 129 947 548 154 431 72 429 131 711 781 923 205 428 300 333 626 599 630 104 91 194 702 718 834 421 414 342 9…
Output: 880497

Example 2:

Input: 320 954 674 394 958 663 451 748 279 724 387 785 271 838 990 621 711 26 555 140 985 975 292 387 574 886 845 546 855 679 923 926 100 417 888 810 154 988 498 529 73 373 223 223 21 63 802 561 153 578 210 581 722 348 858 325 102 181 706 725 342 889 619 917 842 528 272 102 980 903 461 226 674 412 478 596 573 677 71 793 393 433 951 810 746 207 300 379 133 770 315 576 470 364 326 8 171 780 436 365 477 185 376 666 575 676 689 845 129 525 275 526 566 758 899 284 74 794 682 367 578 661 290 235 717 543 188 241 604 445 662 830 27 797 110 468 86 952 789 655 794 619 871 713 895 854 945 454 969 508 337 997 666 626 25 87 586 784 397 600 843 247 612 286 736 838 476 870 914 742 969 453 517 389 137 124 159 744 909 132 157 859 355 455 390 226 731 324 485 889 466 343 773 427 37 309 372 123 566 515 879 958 89 52…
Output: 149046

Example 3:

Input: 2236 393 775 454 406 465 701 948 6 35 914 947 690 917 453 525 291 246 238 985 785 920 462 636 484 718 952 0 444 256 128 855 14 840 311 337 10 419 603 400 748 212 47 678 113 88 703 294 800 817 754 434 142 608 994 217 478 72 847 726 347 740 334 499 411 79 600 296 157 91 175 864 619 445 874 941 643 108 729 59 975 116 596 858 15 311 644 25 222 8 858 856 300 262 353 609 828 998 652 99 790 475 603 621 108 118 518 587 647 648 712 415 523 364 785 295 125 848 770 406 399 729 63 589 99 821 570 143 654 864 311 915 548 499 327 734 422 165 716 399 144 68 680 935 762 985 328 763 127 106 609 587 883 256 284 159 4 699 667 898 839 638 901 646 613 959 933 125 886 461 927 743 179 171 480 445 621 215 130 848 421 38 820 326 696 140 105 718 625 701 718 135 770 718 565 674 654 594 386 484 305 803 974 650 740 201…
Output: 1103793

Constraints:

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

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