CT60491

Gautam's Silver Ledger

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

In the quartz ridge of Glimmerfell, Gautam the measurer keeps careful count of the ribbons. Fulfill a tricky customer order, every figure matters. 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 <= 1109; 0 <= a[i] <= 1000000.

Example 1:

Input: 937 641674 119217 658197 155340 872792 76149 389720 877132 600794 768169 61049 854937 972465 456014 752674 356553 438073 723668 362798 883052 470844 676399 621600 766500 279171 79772 4848 244241 474626 471189 77807 581635 775143 397780 799492 122669 469814 326929 608237 995411 784913 506757 376311 270724 469109 687341 848436 770515 711814 176372 194635 695068 856618 601838 954968 970332 482550 510098 690804 776375 552048 417355 64659 326967 867650 617243 422996 374730 444698 172276 391115 182476 580066 331282 678588 329157 35077 442532 841717 160382 320148 57664 126172 617320 808974 208848 833412 439542 38430 225378 225298 597121 801949 479240 21707 537295 629396 742640 922161 360909 113141 140209 627653 836564 854258 689691 113147 182093 245417 203830 542398 182237 977111 729146 700192 34…
Output: 457413260

Example 2:

Input: 622 22914 54987 810603 770294 259267 863184 353762 657899 690510 497809 332374 768255 201144 923550 498987 481443 119966 588828 807267 644353 228696 829765 10596 30652 244303 606504 501969 109414 589542 42644 329852 129817 935196 996978 736404 927811 65147 745223 972110 1266 411374 108512 23569 585542 709530 842683 561862 202492 425530 425420 524954 518831 331152 297835 820532 495883 691117 957581 883730 488820 889348 727837 736869 489879 513012 451106 250789 251168 551624 958483 576877 465198 947828 563010 642339 760703 857509 687321 694971 250741 594752 521167 311555 417077 22944 783631 304721 443546 891835 631269 687406 456690 101775 822927 300859 483523 501692 444679 997488 986513 193310 492621 313871 293371 56701 743802 662812 429701 817022 641795 500728 760775 822260 54534 828021 189…
Output: 294329836

Example 3:

Input: 680 3293 531350 724383 593833 543687 952198 905428 705888 945840 221631 760063 413098 660176 180391 641904 994060 956782 991675 238027 431471 584099 133962 311406 547677 986301 359796 700965 354641 653159 370862 742603 366049 95052 456454 282913 769264 756576 758670 815200 109633 665375 446780 789861 465828 822407 182358 423990 106092 330763 110286 224174 489906 830182 6945 953836 448801 452991 198595 995846 782366 985108 661198 543490 308694 105220 807918 796673 348220 81554 461366 148535 791634 455383 3644 564350 909572 435736 909728 709554 964715 146366 123919 496489 6011 180110 648277 921217 881033 834228 27429 422718 151437 572112 780210 909880 647026 969278 700181 736248 438459 429717 337863 890146 536900 997601 251838 821347 58399 24911 599844 382549 693358 883063 111968 235977 4496…
Output: 327583608

Constraints:

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

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