CT35686

The Rain Ledgers of the Hidden stretches

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Legend says the vault under the honeycomb cliffs of Beeswick opens only for a perfect tally of stretches. Mina means to find out. 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 <= 3964; 0 <= a[i] <= 1000.

Example 1:

Input: 1981 986 571 677 97 627 655 853 276 220 722 322 891 359 192 59 918 184 247 824 594 338 815 525 384 234 237 588 355 36 612 47 181 506 279 915 260 529 985 244 392 997 951 157 702 69 39 945 557 631 902 33 537 638 140 542 323 655 794 501 435 226 51 63 387 634 715 415 885 860 935 156 450 973 786 619 741 878 626 545 776 138 707 555 236 287 294 874 39 728 210 903 125 654 534 769 747 484 630 246 687 394 561 530 514 189 293 487 97 809 360 993 49 106 683 363 539 942 977 926 50 132 858 217 191 647 737 734 689 237 429 971 452 659 97 430 186 279 668 422 704 191 271 150 340 790 147 902 333 879 954 788 314 179 532 174 159 525 942 793 504 204 660 138 853 797 427 814 920 195 968 793 739 267 555 668 128 764 715 146 34 565 549 174 382 164 678 184 957 999 67 983 464 519 473 168 770 805 930 727 8 965 778 941 8…
Output: 973861

Example 2:

Input: 3682 841 29 660 551 745 888 735 821 61 262 67 319 569 599 942 370 27 801 22 604 878 370 517 355 147 533 786 106 438 177 66 879 393 395 359 728 467 594 517 404 717 597 60 182 214 658 359 621 590 248 52 990 841 301 266 689 813 417 871 680 823 218 878 9 19 178 984 758 888 840 489 800 97 978 543 545 684 925 129 982 984 733 811 945 520 255 163 75 645 825 260 289 456 219 527 927 708 363 342 133 962 32 370 635 967 290 546 4 41 319 47 831 192 401 269 507 527 466 696 363 189 146 89 824 262 70 605 45 617 609 10 252 15 814 629 209 8 590 649 447 683 455 964 776 594 829 746 749 733 789 140 298 213 379 14 430 861 679 709 783 548 214 657 867 276 250 611 291 669 493 736 515 404 58 384 922 506 522 266 659 580 845 668 119 131 85 213 480 672 671 317 799 540 706 668 473 760 291 709 837 789 924 384 851 782 474…
Output: 1802570

Example 3:

Input: 2047 936 936 867 332 558 774 947 583 869 464 424 873 62 502 537 268 235 302 51 124 941 838 815 212 286 273 219 287 991 720 590 977 843 313 316 551 815 347 93 52 860 89 643 102 61 863 923 78 816 31 484 893 25 730 35 997 483 58 408 97 634 286 743 930 151 289 610 880 154 558 498 352 160 683 801 98 953 931 538 895 175 101 996 32 226 42 964 543 207 185 280 910 691 684 85 506 541 234 755 825 189 320 695 904 520 986 317 816 245 950 709 633 36 212 735 106 655 335 840 278 115 724 808 527 913 334 494 494 669 671 8 746 309 719 406 35 382 391 241 926 265 292 263 898 797 86 637 591 979 309 614 511 943 257 828 453 478 45 25 108 795 907 353 290 862 74 373 965 129 567 496 24 641 813 947 447 434 741 569 941 229 964 48 839 23 980 679 298 101 295 628 678 989 57 509 485 62 841 172 255 943 934 801 795 787 279 …
Output: 1036928

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
The Rain Ledgers of the Hidden stretches - MEDIUM Coding Problem | CodeTikki