CT46852

The Rain Ledgers of the Painted panels

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Before the gates of the indigo vats of Bluehollow close for winter, Yami must finish the panels ledger - one figure at a time. 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 <= 2620; 0 <= a[i] <= 1000.

Example 1:

Input: 1486 732 76 798 430 1000 766 640 621 144 57 938 906 301 198 332 890 450 613 621 238 794 557 356 576 242 726 381 456 113 792 709 317 702 778 824 365 450 861 142 433 81 417 89 712 574 507 339 941 155 89 931 57 63 124 865 425 363 216 726 704 138 772 854 628 187 506 83 15 173 794 206 847 684 321 911 119 840 355 538 921 305 876 737 428 805 434 855 303 614 747 83 591 733 135 567 908 699 739 826 0 100 718 842 196 295 553 375 291 383 194 35 999 125 920 71 461 722 206 650 604 234 345 568 351 602 363 401 461 604 256 643 624 341 641 465 172 491 255 189 673 507 694 308 630 121 730 280 393 704 261 35 681 834 720 614 622 475 553 177 889 766 467 727 378 966 762 56 1 953 637 442 130 428 224 551 943 798 886 171 482 825 660 947 69 872 892 180 614 715 931 601 935 855 394 531 640 932 670 936 798 800 984 284 9…
Output: 725656

Example 2:

Input: 1787 459 955 344 395 485 75 84 267 510 647 573 230 214 515 336 323 848 578 365 33 146 676 261 42 738 527 488 770 680 341 98 779 279 970 408 933 930 768 264 533 121 670 204 985 855 208 782 49 820 236 364 876 415 552 30 714 933 223 536 595 706 945 425 956 311 121 894 811 860 126 6 209 758 733 181 218 675 686 362 941 144 40 533 794 688 910 540 445 818 165 951 29 305 579 68 265 253 723 494 945 440 19 835 150 664 992 62 159 561 574 860 684 326 272 139 523 402 468 530 473 240 21 548 283 370 957 591 277 342 311 500 797 939 519 186 0 704 466 103 254 692 725 843 848 671 527 327 277 71 396 124 693 798 960 538 717 948 344 372 256 885 27 16 242 614 965 761 894 677 487 164 309 576 820 896 297 661 405 527 381 146 678 755 35 649 73 439 493 680 516 795 734 191 576 264 163 354 902 537 866 367 85 749 376 93…
Output: 884391

Example 3:

Input: 215 327 33 964 200 2 191 483 398 319 470 554 240 910 693 408 705 923 449 846 13 964 405 697 864 506 539 963 163 136 325 892 594 592 105 813 708 49 218 282 493 671 883 763 73 773 809 288 386 559 763 425 786 157 505 554 586 848 73 817 443 993 169 30 881 716 277 578 721 710 305 659 468 693 946 407 941 487 844 200 471 629 317 831 828 916 340 568 634 292 433 682 804 980 641 348 412 438 670 920 416 894 459 677 792 985 451 972 911 780 741 40 49 797 516 592 869 139 14 836 414 986 649 23 340 738 304 396 956 452 111 596 124 714 62 108 417 436 601 11 523 378 55 492 157 307 900 574 843 131 690 315 246 919 594 93 482 545 119 660 665 593 713 309 372 8 191 545 598 907 692 148 453 526 951 706 228 100 871 177 29 633 853 219 994 751 695 519 317 845 785 742 46 179 538 434 945 367 99 164 705 233 936 584 490 1…
Output: 96557

Constraints:

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

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