CT56892

Opal's Sunlit Ledger

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Opal inherited the gallery at the orchard lands of Applerun along with its curious bookkeeping system for stretches. Time to make sense of it. 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 <= 1164; 0 <= a[i] <= 1000.

Example 1:

Input: 1059 718 904 157 783 544 341 21 958 612 319 128 675 59 961 100 210 562 807 537 860 105 272 110 798 66 503 764 784 482 768 386 932 111 989 454 595 128 349 162 826 133 670 156 931 524 975 984 497 394 45 402 38 853 522 655 654 629 132 570 966 235 272 620 702 856 976 225 893 502 641 892 959 844 681 830 166 117 152 802 256 519 915 148 306 782 942 451 543 284 137 138 906 642 413 442 14 80 776 208 733 188 757 788 709 284 248 344 725 748 629 966 691 504 933 440 739 917 369 602 580 199 990 924 64 675 508 368 320 162 517 922 164 306 764 758 838 484 442 204 156 968 37 663 456 521 418 351 312 367 354 437 878 981 70 956 864 396 812 588 594 2 627 820 34 603 49 444 0 436 277 39 639 734 273 984 287 375 276 65 997 784 179 557 448 154 104 49 223 1000 706 134 879 19 863 542 746 53 945 362 420 739 115 842 925…
Output: 511911

Example 2:

Input: 1053 250 210 711 809 423 349 756 305 187 185 793 347 859 963 428 208 348 999 936 214 922 523 916 760 59 166 702 641 651 602 580 728 579 430 244 844 446 454 57 536 141 348 464 916 72 709 837 791 452 943 394 715 49 43 783 514 106 361 175 54 64 523 273 998 994 30 84 506 43 959 502 428 360 299 748 844 731 349 479 561 565 854 651 931 188 572 180 974 0 369 110 309 588 943 870 737 897 788 712 862 867 920 682 726 653 671 122 193 74 585 830 795 764 252 107 360 409 850 678 77 41 121 380 287 13 107 516 402 49 954 764 434 598 677 53 115 31 685 85 623 793 852 82 577 901 545 52 279 787 418 691 684 73 378 456 651 652 791 155 735 471 697 141 978 363 943 175 406 846 933 102 194 800 572 290 334 844 513 354 571 395 593 798 197 673 970 438 426 604 313 194 778 758 104 817 100 627 755 61 752 141 94 807 500 462 …
Output: 516782

Example 3:

Input: 793 439 176 140 310 311 655 870 827 337 29 98 536 785 792 295 735 508 571 824 629 876 164 447 587 152 911 952 487 857 844 95 512 792 582 523 940 31 459 4 116 850 296 932 60 345 135 643 446 894 461 142 757 993 538 223 361 58 582 11 266 799 164 709 842 969 887 517 827 79 970 810 273 837 399 975 924 109 745 483 641 432 876 787 870 200 623 797 39 712 822 293 283 134 591 58 599 329 786 612 467 163 568 495 628 907 467 520 482 837 700 88 110 951 237 695 750 528 443 569 523 789 614 634 246 114 867 782 354 895 989 692 656 331 100 916 923 117 604 149 737 546 611 380 222 852 692 226 229 746 894 418 563 834 496 990 508 431 299 79 554 771 280 359 66 242 862 139 874 44 830 216 471 478 740 71 349 617 783 264 867 543 618 991 83 142 258 312 189 92 408 21 733 702 453 58 622 454 985 216 542 628 388 958 887 8…
Output: 390855

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Opal's Sunlit Ledger - MEDIUM Coding Problem | CodeTikki