CT35609

Last windows of Elio

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Elio runs the timber yard at the willow walks of Reedmarsh. Today the books show a list of windows, and the numbers must be worked out before sundown. 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 <= 2466; 0 <= a[i] <= 1000.

Example 1:

Input: 2016 217 787 20 122 491 566 530 941 564 426 902 541 809 877 29 777 316 515 891 53 389 717 215 977 437 778 939 876 884 853 935 641 179 667 784 971 614 705 659 778 898 331 702 785 25 62 128 195 617 901 43 257 97 676 381 203 243 401 416 6 39 119 385 955 448 679 906 82 392 482 776 803 295 10 580 733 199 18 356 211 875 418 608 772 975 498 696 262 600 379 522 325 275 868 701 853 289 661 318 517 872 44 998 705 830 590 637 664 79 331 893 356 254 2 150 929 356 478 603 758 701 990 996 69 873 394 31 629 40 54 577 495 197 796 384 882 655 939 505 461 387 712 264 754 181 42 441 49 253 268 69 312 163 210 522 689 313 625 217 768 907 723 875 887 707 131 397 322 171 725 381 317 97 422 435 124 926 576 762 951 630 944 163 619 830 121 143 133 103 459 949 276 476 201 811 972 963 383 131 83 694 626 920 575 376 3…
Output: 979009

Example 2:

Input: 1619 591 953 791 717 608 807 975 328 753 637 430 276 42 891 156 239 55 988 124 762 90 617 728 78 767 365 153 622 869 785 524 731 662 15 547 652 532 918 796 585 148 782 353 455 702 375 200 280 631 164 596 133 768 89 365 796 311 143 787 35 381 421 3 675 396 420 136 202 489 874 578 444 983 502 977 990 563 866 95 370 43 30 258 158 366 339 846 847 915 346 27 282 610 575 412 631 213 678 321 816 27 692 928 678 706 859 855 79 769 558 998 439 752 6 973 271 416 411 16 173 987 424 925 917 617 118 732 68 667 267 725 798 315 774 688 989 740 745 519 717 133 685 695 757 316 193 314 820 323 101 701 239 179 470 109 477 952 792 44 961 434 996 456 222 657 812 661 589 137 545 352 438 765 532 569 33 788 320 184 689 860 89 616 511 746 805 588 135 895 826 546 607 826 795 631 3 390 316 578 561 257 417 312 874 86 …
Output: 812309

Example 3:

Input: 1323 552 914 7 107 37 162 95 362 885 747 619 937 391 39 312 168 463 472 698 369 780 613 182 785 752 564 844 886 679 848 490 866 109 996 945 564 213 868 366 100 35 989 40 422 469 252 321 746 617 192 8 158 141 562 433 680 907 786 763 843 473 708 12 482 542 401 669 870 254 181 208 479 182 292 544 564 331 701 263 159 797 394 536 299 378 230 741 27 342 98 904 100 482 752 421 916 975 484 232 432 512 758 81 91 946 553 671 498 718 358 472 229 578 261 4 886 105 30 262 61 876 704 754 633 589 414 280 797 242 491 796 344 969 569 864 434 762 925 740 435 99 310 911 378 740 28 804 331 380 86 594 259 461 537 335 988 33 591 140 877 544 911 91 574 366 908 168 33 382 531 177 700 922 58 86 708 621 245 797 403 552 653 259 1 830 217 669 265 216 429 760 226 84 791 265 69 38 781 811 375 470 522 62 298 606 358 570…
Output: 655040

Constraints:

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

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