CT58960

Last scrolls of Iris

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

Iris inherited the apiary at the coral atoll of Pearldeep along with its curious bookkeeping system for scrolls. 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 <= 2215; 0 <= a[i] <= 1000000000.

Example 1:

Input: 1193 967501728 145256382 384061597 794839457 114333717 172519737 25937363 190532530 873232843 450631472 40660987 154141220 300034669 83720545 446877841 42700214 25009160 380012171 34990709 418536950 707398986 964804444 502179930 650850287 83777508 76329801 272105171 166190549 143877994 601524359 731723458 999447769 66339752 125631018 817955804 754350026 109333078 670727972 833775418 65081093 356744860 820429329 587305831 820240845 865925051 953515915 575647451 583891223 171159697 251616444 411224565 985152214 719572174 871469580 29083577 298729100 663149579 525161896 356039433 906293729 334941744 137830373 157733652 136549621 242386353 974587985 170721343 582145836 649871852 431472558 256347021 519112593 961802005 59380510 512204310 311540774 330029785 708243469 992886715 197524599 9937686…
Output: 589160297058

Example 2:

Input: 927 237302219 935656777 531155844 989713740 669818830 608851738 666877950 158407088 433775034 828316998 804137642 981552953 773280999 893985986 865385015 717661346 306368818 14372477 79869915 793413200 486473489 54577255 359514687 672670436 335667103 586142612 362302915 904605785 984482187 371439924 421805835 615001116 44675399 854314297 716510812 426072185 200434033 792554168 445388300 350521642 610859849 749027018 637291668 832477340 652989784 961568611 189996779 306863241 330166295 525212783 271098052 688979286 936156190 94608894 860208067 267703865 500243676 164937814 633449791 303104161 61420745 932264466 548405367 956566565 712858162 34599573 211078113 97050041 455969325 157279211 920432939 609542288 12034259 908621398 871018647 114136995 841396981 841216489 910490544 347108183 78594…
Output: 454580734767

Example 3:

Input: 340 705080964 92780328 426638516 145977637 940071257 532474793 518723123 385510588 218936089 143062605 64358413 954255918 801736574 22654925 309117397 473838933 959512110 184569976 322648697 750501567 765858143 169175764 916935974 945204663 928135648 796470030 887837357 213562772 143801387 953663321 777993154 82095485 36084602 455614352 853763818 316596378 660656201 498238844 985972201 111914252 557810173 502596590 15546047 982338061 810886405 662736983 385668364 80628209 621614521 164230347 137152473 1625885 306030202 315514245 105699155 277170356 434889131 759858424 296507625 949314098 654955129 141982766 372616858 744909216 338542204 728972444 203326188 822000167 869457095 217801017 895403390 822661508 936900341 335315850 704601373 738676027 628699243 479814017 492753416 508862556 96338…
Output: 158531394405

Constraints:

1 <= n <= 2215; 0 <= a[i] <= 1000000000.

Loading...
Test Cases:No test cases
No test cases available.
Last scrolls of Iris - MEDIUM Coding Problem | CodeTikki