CT50787

Mina's Rain Ledgers Ledger

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The council of the fjord village of Deepwater pays by the answer, and Mina intends to earn it. First: the full register of panels. 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 <= 2016; 0 <= a[i] <= 1000.

Example 1:

Input: 350 457 474 721 439 867 498 839 872 738 35 400 816 49 303 835 582 139 303 140 842 958 582 764 408 646 457 715 783 794 514 684 103 55 476 320 431 577 887 437 73 402 660 86 810 45 19 563 377 338 918 287 423 248 667 718 271 890 75 884 278 765 838 742 542 649 897 663 591 455 143 708 78 459 68 5 328 104 457 186 520 404 605 324 454 90 571 722 675 658 750 573 139 776 671 275 881 198 899 346 757 110 39 981 581 248 522 861 730 507 242 691 417 400 940 649 258 569 224 520 782 644 991 475 649 50 534 907 225 61 213 224 37 890 989 706 745 913 941 281 829 849 179 512 945 123 826 853 60 809 341 33 377 340 446 151 648 186 443 708 504 817 574 642 280 554 444 809 259 497 439 751 333 495 453 473 333 170 345 33 997 220 291 24 614 364 753 786 486 793 58 768 201 1 86 873 421 130 462 60 449 169 192 151 460 147 58…
Output: 171058

Example 2:

Input: 606 642 926 880 750 625 181 516 345 583 545 819 65 853 449 886 93 565 963 527 970 662 682 631 520 93 502 989 566 797 564 121 884 657 157 247 604 937 764 309 791 110 518 876 829 682 196 844 637 273 910 107 221 407 536 522 332 718 47 546 328 992 15 795 984 681 738 421 814 446 530 77 485 791 377 816 911 452 275 225 859 460 588 686 768 328 979 844 848 911 590 13 281 191 457 78 936 517 856 590 540 853 691 264 945 430 749 141 819 810 481 463 901 999 413 396 880 325 637 655 920 760 530 539 749 65 949 486 663 580 580 882 498 136 390 251 120 205 844 70 336 529 764 472 199 428 43 728 642 618 571 5 689 809 539 205 200 858 155 974 615 881 91 810 818 337 995 346 615 498 501 266 976 525 66 656 467 260 646 344 398 34 778 168 615 260 620 702 420 753 965 214 53 296 574 693 544 314 0 325 673 513 478 779 24 …
Output: 289619

Example 3:

Input: 764 166 368 12 117 791 692 648 934 190 677 171 178 470 315 458 142 418 416 944 863 800 812 76 935 220 74 2 821 413 585 919 493 770 893 205 773 769 260 87 742 797 789 80 678 297 784 458 314 359 501 469 493 163 338 847 55 142 469 659 539 329 330 813 40 128 811 480 770 57 191 457 535 25 140 507 934 420 593 98 385 925 730 920 124 71 715 635 991 384 763 791 381 271 323 435 971 803 479 876 613 866 222 909 801 233 242 432 781 625 506 822 647 600 871 240 296 92 266 579 474 551 976 107 29 54 931 495 143 236 844 980 695 890 764 611 208 761 738 131 848 467 631 621 992 967 942 153 292 726 779 42 358 879 448 532 818 778 503 925 119 850 12 199 837 567 944 811 932 203 769 465 662 31 781 529 124 357 949 6 485 753 469 538 458 725 710 861 297 311 468 668 938 691 185 523 392 907 585 958 747 547 905 797 353 1…
Output: 363613

Constraints:

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

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