CT47599

The Ruby Rain Ledgers

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Manav runs the mint at the crane marshes of Stillwater. Today the books show a list of scrolls, 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 <= 3300; 0 <= a[i] <= 1000000.

Example 1:

Input: 1457 358998 169500 694843 657235 417472 927172 464848 288256 76329 395268 450302 544019 226867 892269 530972 978053 439745 541714 821281 117554 760432 350798 559910 89047 866358 409329 87393 694659 783992 538289 296744 299868 799126 928451 699535 451160 772729 732391 792173 235201 221489 19580 585567 269224 878842 876100 401665 807586 712486 706933 265778 142539 935528 34330 273041 253019 176636 658107 429584 423354 850858 907173 66489 16835 455404 537747 968142 618814 282517 462381 897759 553778 528058 744957 692069 831906 564519 848592 317153 60963 411433 473531 359827 196135 377511 642647 962780 39323 709263 659141 588289 852794 617864 203137 85479 240687 717282 64006 716215 541680 125814 621903 887967 971982 542361 272504 844881 803265 113192 437614 572751 719938 331787 297729 628476 1…
Output: 702535212

Example 2:

Input: 991 814122 472774 423450 285139 950663 317782 345618 468162 672212 909967 177869 171624 53009 295241 874728 128752 571589 29980 110758 80659 606172 678557 490564 793628 589567 772786 594308 307001 891319 345357 597277 784605 612366 684640 683547 708237 306290 993953 457328 867754 635641 323688 594897 123762 862504 311061 969593 6730 554725 479863 533984 74460 309590 17952 286779 896678 206486 183477 621350 712773 775736 690544 876746 263772 278495 495288 788883 55060 161704 230648 82964 274391 822412 812159 647961 265198 449095 583990 399789 504214 224065 163929 797298 787828 348767 131461 147476 155457 454287 474976 141497 422976 804866 304479 117306 269187 798572 706830 553714 850559 991336 324768 325141 216890 731003 729136 968668 913602 658913 324443 225734 949938 460887 360095 603263 …
Output: 494965526

Example 3:

Input: 2489 415314 558721 786063 410870 584148 317785 301500 968150 112726 159961 479174 120391 68242 324793 134172 208589 11757 310030 14127 362538 719689 182733 314008 413752 28386 417108 711743 417536 304780 141852 848889 758029 179190 631947 157986 311188 375994 870836 229142 581753 484154 910647 61406 259149 939238 109449 20528 454188 605771 248540 211613 759862 601999 616448 941029 748401 229 391386 986931 259689 702343 893662 8465 810219 529531 553746 532775 529574 873738 296725 375479 465054 512281 704049 165391 830263 298215 353540 439166 711541 965667 807415 270323 97821 600557 897500 903690 837875 764874 966129 838044 947789 752783 876021 600014 360409 772252 994792 451200 254948 104239 120900 938305 988058 758219 359033 483228 963432 29481 215828 768357 411751 457133 594726 763204 272…
Output: 1238070797

Constraints:

1 <= n <= 3300; 0 <= a[i] <= 1000000.

Loading...
Test Cases:No test cases
No test cases available.
The Ruby Rain Ledgers - MEDIUM Coding Problem | CodeTikki