CT60583

Trader and the Brass scrolls

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

At the spice bazaar of Saffronia, Trader records each scrolls in a worn leather ledger. The guild wants answers, not guesses. 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 <= 1829; 0 <= a[i] <= 1000000.

Example 1:

Input: 1031 480961 885371 997519 265896 809115 89022 362374 306424 883304 842319 748397 16482 832423 27387 522242 311028 493039 332039 603729 47310 2789 621931 410507 414596 915013 376878 850400 567553 167732 639000 201333 259487 963363 6037 946855 558061 108315 390118 245796 982195 542899 900840 966943 859668 568414 715242 379281 988505 223775 204079 30149 251397 371567 836088 656277 80326 974310 23355 577783 859003 150175 270451 886952 475125 943763 913412 870995 384195 544626 374634 66470 980967 742828 664843 201442 595804 14768 733900 594788 87645 121000 558071 249134 884322 801988 144614 584080 960983 189467 652453 199011 450732 263866 42540 12697 736734 352239 119787 7901 371001 526826 953543 834915 22570 559694 148559 836489 132465 992570 912693 243557 526175 329075 356645 671236 747095 23…
Output: 504383940

Example 2:

Input: 1301 812648 793561 661617 531788 394764 661139 763077 270168 142385 496008 642765 378058 902611 356447 804089 18738 415051 123855 757551 847617 32665 16017 574334 761496 768432 720517 840100 375719 924141 628892 61428 405694 51445 171938 716244 459027 124239 239962 377207 235080 678904 672478 962434 696655 766227 484303 684459 193425 585086 500330 668104 868272 273875 560538 885988 320112 139938 827863 425486 379173 62957 134058 518604 595587 984732 480058 492616 79332 222514 501692 437065 408511 174709 363127 726654 541448 729457 671658 800200 955244 995593 600648 247111 564818 296293 34777 21922 390680 330858 744321 720760 132777 451138 959296 700101 939094 540537 517277 933737 872393 920825 48067 79724 914041 220951 48759 101795 334590 636995 880910 781699 783265 622728 404388 617845 27…
Output: 632869173

Example 3:

Input: 709 562999 338330 993928 173015 214459 400550 773634 598771 387152 554140 434223 13072 197340 547013 518258 619744 544712 232786 147587 760480 867944 584238 375144 683705 685057 155953 373168 640980 377108 570392 258626 4968 314248 195079 805340 376962 686758 387658 498077 176418 764718 590870 193813 661206 601518 492582 871001 830504 631714 815751 348015 413568 975172 512861 797842 268867 200975 591890 213711 415851 498442 963748 977799 675542 859972 129887 184476 159095 453977 262694 216404 256582 564579 346100 609197 125660 511662 805146 156677 269650 643356 396449 945681 814821 782970 746141 661329 962405 808236 742227 871765 221421 622876 762760 566001 753965 559545 48840 880606 477144 117743 358031 801017 346060 570411 783776 3004 134151 970394 256505 239747 440040 886628 242204 2524…
Output: 346629575

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Trader and the Brass scrolls - MEDIUM Coding Problem | CodeTikki