CT53636

Neel's Frosted ribbons

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Deep in the cedar groves of Balmcrest, Neel studies rows of ribbons entries. One clean number will settle the guild's oldest argument. 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 <= 2252; 0 <= a[i] <= 1000000000.

Example 1:

Input: 2185 429138734 89774098 986273602 29294910 963148422 724468689 941817627 986512190 260369596 368642593 103963720 695457829 374602849 334955977 174850267 48881869 651242152 363567602 96248140 1438648 429702684 944978910 95754119 939979808 983120030 178976744 971812443 149063740 227988596 189883840 269385974 894937854 18059619 171733796 88024071 57418081 391803393 537693532 451039697 150911431 700809951 465527510 821858441 346499694 855527 765884715 908779841 459810663 347969601 295578708 127140849 878107308 643403762 222886527 836925211 822089071 835006889 142109220 950839600 485876455 479808493 926084050 41349037 489442037 712501285 424235243 564401373 81975336 237255907 463451359 339435146 483998254 441307760 238136468 264604529 501418281 967725474 278845930 609397059 308703729 35026217 5…
Output: 1075609245457

Example 2:

Input: 48 491023965 723404267 776976712 593970938 668684044 506503965 933568177 16620488 57860271 96089164 802540865 223351865 93736105 486389896 923775773 798156506 904636245 338304798 212375214 173239166 582991354 199791850 232994352 481073583 865951757 512295636 850303939 371643489 191698054 294756778 101346269 149567331 395531667 182659741 136370095 918870513 795876463 406905490 209914536 40382656 407611348 138952139 31378108 498771731 303506306 809063881 410510326 639339359
Output: 20330440567

Example 3:

Input: 1330 871442908 998133362 792240921 701444409 525637850 370026963 907445406 904486914 209818407 521871341 874367220 341125762 706925884 903885291 601119965 903143729 583559292 92327747 552590172 689948763 437164004 866895208 156631115 937460643 350972653 389845789 899331229 262144897 884841175 166481002 198782200 720016931 919449119 271373267 527704906 752586579 915700546 936639429 945690349 454009189 48322141 91999974 418612972 849768293 548689693 761667184 81201190 686621508 404968968 733321401 67364344 667120594 840166991 476422630 347213632 526464231 416459876 335217438 235111751 553540733 909960291 230298337 862415850 488172034 460398757 646244190 78678665 548580674 465110511 564761244 270833474 699183542 374555768 576622168 543979857 862012172 88617000 17701910 44999343 27699633 91589…
Output: 662001515480

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Neel's Frosted ribbons - MEDIUM Coding Problem | CodeTikki