CT61376

The Rain Ledgers at Firewatch

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

The harbor bell rings at the caldera rim of Firewatch; Petr weighs the day's segments manifests and starts the calculations. 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 <= 1075; 0 <= a[i] <= 1000.

Example 1:

Input: 618 636 690 70 224 320 336 462 746 90 819 700 529 637 564 343 358 320 871 664 889 816 794 634 710 104 613 659 687 495 144 241 789 59 178 950 983 424 534 51 880 609 125 548 89 533 251 407 676 836 808 206 826 530 160 550 843 395 359 260 221 180 13 895 795 730 714 330 32 942 463 903 683 783 934 730 322 218 956 642 790 90 938 596 6 298 45 648 71 719 35 711 180 760 806 827 592 232 852 572 879 169 518 905 657 409 148 86 13 782 371 577 86 380 322 951 956 332 834 724 228 229 205 560 163 726 741 882 615 44 847 772 11 311 514 424 813 920 388 631 595 629 361 48 473 983 642 2 123 518 524 583 772 305 486 80 854 132 568 800 819 383 304 750 728 131 264 586 189 677 418 555 21 363 827 949 263 53 684 486 954 803 682 892 127 696 318 672 30 999 592 66 847 329 171 636 618 595 869 499 92 584 664 791 942 524 819…
Output: 285884

Example 2:

Input: 477 256 383 133 338 448 117 638 998 458 488 705 958 750 866 195 828 990 863 912 127 417 528 315 256 459 347 444 156 407 325 251 477 892 303 482 803 725 626 39 949 902 862 589 852 184 357 376 588 482 822 615 904 756 173 753 441 219 197 368 665 802 814 786 704 37 123 991 407 801 666 313 141 283 763 414 846 407 545 866 767 677 992 98 15 869 641 449 337 697 626 1000 819 661 602 458 270 81 377 978 805 428 679 782 214 289 168 80 536 173 24 601 54 123 93 741 539 838 559 74 331 158 248 148 352 310 86 905 50 792 162 909 650 628 706 186 261 244 121 949 771 548 241 713 518 434 254 855 35 502 441 525 360 605 46 914 343 769 886 687 308 885 712 919 499 448 849 847 580 392 222 47 269 724 947 777 115 720 537 576 385 154 56 531 880 3 374 251 38 699 350 678 844 489 309 376 579 310 580 345 521 527 333 76 809…
Output: 229226

Example 3:

Input: 466 723 111 276 333 823 4 257 746 923 658 86 818 38 413 530 865 774 825 739 599 95 719 936 698 901 985 966 239 628 859 730 732 173 542 336 758 258 911 423 267 481 382 831 731 642 822 121 225 94 556 71 102 468 729 573 886 868 989 710 278 960 786 727 676 427 344 691 892 441 312 537 289 922 819 326 333 867 979 659 621 782 313 382 978 948 32 244 98 7 644 836 743 478 300 721 202 582 27 559 848 952 204 528 428 864 659 336 448 160 735 945 824 126 570 28 286 591 184 902 310 280 630 333 196 742 548 621 986 413 570 778 9 849 236 681 761 669 304 173 396 38 889 488 115 984 951 573 722 245 587 221 122 326 937 288 674 952 155 183 808 679 242 635 678 541 729 442 61 452 38 181 387 226 753 731 463 733 824 823 20 427 301 109 154 751 248 802 502 941 902 539 964 149 0 519 597 323 855 904 12 132 1 137 446 519 …
Output: 213989

Constraints:

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

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