CT64654

The Jasper Rain Ledgers

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

It is audit day at the pine barrens of Needlepoint. Zaid spreads the segments records across the table and picks up a sharp pencil. 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 <= 2064; 0 <= a[i] <= 1000.

Example 1:

Input: 1439 290 967 823 775 311 764 891 168 855 138 807 519 835 41 168 471 637 282 282 140 128 512 101 768 162 598 4 198 285 234 770 283 995 142 35 270 606 896 55 633 422 538 666 609 52 580 948 389 392 252 873 36 953 502 795 339 250 567 216 31 952 111 608 404 710 889 736 570 615 220 521 664 964 868 221 75 969 909 674 618 403 687 320 531 177 563 411 601 212 850 353 335 397 999 793 908 737 177 297 426 829 983 338 553 695 662 608 297 470 706 789 619 908 596 882 455 62 195 719 190 78 886 5 900 108 844 9 772 569 448 757 621 311 143 459 13 469 845 918 365 668 74 940 864 286 418 185 10 25 862 300 669 492 734 198 603 831 343 995 660 416 671 432 317 21 325 391 999 502 970 784 201 165 702 567 779 754 679 360 119 124 330 308 122 446 293 123 790 761 28 162 854 202 952 91 820 288 923 975 623 189 756 512 677 3…
Output: 714378

Example 2:

Input: 885 382 165 300 702 519 641 333 954 507 795 469 710 206 237 115 330 570 717 49 193 339 751 20 193 396 129 483 667 564 908 230 735 692 136 513 657 116 757 51 550 794 586 506 89 840 371 526 458 72 793 274 252 902 649 103 846 448 64 274 932 58 469 188 259 193 516 499 139 736 244 270 427 359 653 723 799 928 856 472 493 36 720 929 712 701 908 118 596 930 663 432 543 924 79 354 9 792 464 491 104 774 758 792 824 307 630 22 880 623 672 167 505 870 756 309 122 944 8 145 823 6 868 879 774 464 602 888 724 491 232 687 398 45 387 970 744 63 409 110 766 345 729 117 655 337 458 995 264 331 327 193 679 212 372 954 284 60 486 737 661 730 576 961 895 696 784 960 586 852 582 900 632 594 36 746 362 995 664 239 365 631 242 946 583 736 897 900 903 149 19 232 970 107 180 537 750 425 473 947 431 329 232 117 471 6…
Output: 444666

Example 3:

Input: 1905 86 89 932 332 887 569 94 636 587 882 219 945 280 648 410 134 56 13 254 710 455 823 823 980 517 552 450 864 646 562 715 219 566 977 403 538 856 337 592 505 715 73 484 450 55 341 477 713 169 111 88 220 882 104 121 490 170 537 603 941 790 517 440 85 843 210 390 749 237 365 333 561 57 214 942 127 630 580 66 621 354 399 340 588 736 772 71 264 314 448 140 700 658 760 956 166 42 700 39 788 884 163 686 917 292 132 717 854 120 903 672 814 48 710 79 382 294 986 205 23 954 862 552 656 176 271 528 908 901 644 529 624 67 82 237 510 141 454 800 494 696 122 928 612 861 440 331 780 757 175 949 215 241 1000 835 92 684 135 579 674 388 813 705 322 136 676 226 135 241 883 27 581 372 492 426 597 286 152 665 621 568 74 976 889 260 729 743 33 555 15 877 746 100 819 40 791 282 165 586 502 389 209 593 744 469…
Output: 929235

Constraints:

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

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