CT58555

Mason's Rain Ledgers Ledger

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

Caravans arrive at the trading post of Goldmeadow with crates of stretches, and Mason the surveyor must account for every last one. 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 <= 2840; 0 <= a[i] <= 1000000.

Example 1:

Input: 1435 328186 101744 266220 586772 107624 875806 519157 562075 572478 722529 141472 350726 173476 982793 644583 944277 732638 232361 734570 547152 630413 356307 826857 182270 579456 452631 992795 380169 895857 702015 861984 863481 847064 368606 452257 117136 13676 959492 903387 362368 954657 635485 962695 286665 179020 186102 625084 868791 336594 209160 153092 716511 273291 431357 319206 791231 75844 809368 560355 879440 613398 988112 761193 366246 597956 161349 945900 955844 915767 527618 366796 971551 5264 312707 258441 616859 5257 787305 92057 269805 394066 802786 104118 608091 699255 883687 995299 767272 638850 232749 512172 101672 540683 988996 467392 462048 252379 194424 884934 554858 576515 460556 883863 980272 113808 678821 542678 988990 167425 970737 391808 175178 8697 69100 936054 …
Output: 697705288

Example 2:

Input: 2077 391595 258046 389325 144764 395116 897920 772898 159750 835349 230910 907955 279324 809679 258010 454875 292560 190875 882874 15954 287835 507996 19475 362117 962290 715196 881426 423000 965757 93092 4871 377367 879361 487856 678353 833985 879192 758979 741635 41930 546250 784094 920532 913325 75294 751026 20615 738623 584884 399236 945083 618205 420768 265930 119325 566260 919952 578685 675649 930036 982089 324149 228432 755395 856407 267196 711937 803247 151472 194200 370682 662277 580158 191485 599097 614461 110402 228096 746222 828656 868792 578424 939866 662673 190647 796917 166860 530541 995869 382019 983249 935273 416184 865763 494644 797265 317746 673660 386901 586777 674571 956340 855809 157776 536040 256518 934918 368070 904655 254239 917893 89713 180814 206951 192374 271262…
Output: 1009763589

Example 3:

Input: 485 363398 303163 783775 569631 197693 549965 801390 409375 607791 120883 324382 818849 793828 366817 215521 565252 217510 66244 291585 557237 95734 501900 209991 300278 823373 600444 205986 106021 332146 964833 861478 586963 87263 646695 485325 36938 996763 458145 697626 871295 200886 146814 409647 982256 272957 699854 464652 572953 111369 451399 756133 523709 850515 820784 416390 778072 378641 757452 397235 552517 779000 283918 113634 994248 409850 642332 971808 772796 652051 199704 6746 300442 210265 646488 942960 609076 447407 40374 957859 358496 622337 3836 918030 44346 454115 785801 292071 531408 481895 772271 713772 905629 339721 164540 891277 557245 597653 320566 220043 531219 378465 99763 954246 640724 607870 87646 680390 446095 403931 360690 939165 284951 425244 28595 374236 7475…
Output: 233490823

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Mason's Rain Ledgers Ledger - MEDIUM Coding Problem | CodeTikki