CT64762

The segments at Caravanrest

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

Before the gates of the dune sea of Caravanrest close for winter, Orin must finish the segments ledger - one figure at a time. 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 <= 1034; 0 <= a[i] <= 1000000000.

Example 1:

Input: 272 890550428 252482867 53770951 712470320 103266041 652205901 952914388 502028209 203154569 543375505 549988709 364105769 756697486 74394929 95975005 934568933 953647931 943696160 188793066 623412368 719935508 882900590 35938764 871731407 69461938 142138760 677495533 877866895 74622088 965254497 412049648 978356257 563157493 111879598 619426029 216110711 399519214 888962698 29687864 825833574 332279375 373670020 285006055 521131080 62225687 321261497 414335723 958240807 751286500 944829624 919465447 672673413 862896777 414647416 992360697 37341328 312545087 460319 568676202 880848500 848441892 606606387 312413545 188317870 493695443 862949602 835159081 26274262 884988127 355938851 206602443 426570712 374365648 664009253 635904719 766855526 824712589 66230212 55513212 674202796 24248477 62…
Output: 119473243724

Example 2:

Input: 785 213493745 628707467 927556070 308566939 554132485 13681101 188026997 277929293 541920734 38545260 885793185 561929167 872663368 710223239 999036497 45647214 254015171 144754041 988582828 414822840 259171348 810303510 612551673 677955416 812141627 686137125 188753255 388201395 568445532 212555533 602720774 748519489 69457902 704766528 402410449 854627740 87391194 612687820 665374866 645047475 818443496 818456640 375410013 918694689 402937665 351038472 505232637 511483544 231682992 436725144 325728041 978727811 628835671 301592591 169451794 739670551 679692525 246464665 218894035 775607560 710457986 757729377 45115373 850064789 980195750 37420093 740411028 204808297 404630152 426208417 747095957 190597793 804042358 940694565 543383707 792351551 696896672 792233417 835220073 460323215 190…
Output: 370649513155

Example 3:

Input: 786 151082832 572312634 99898980 138252462 871162318 59667379 6913540 801436729 18852099 34278284 667890990 164609462 7959079 933598269 767141514 152822064 878399606 390049838 614203752 136602748 369169957 12085623 359037001 846064038 320375386 101157578 890756705 547089976 865554700 596287251 733654845 266963685 405398353 642695726 795604408 490424430 400106470 206396866 404488761 586519746 643583339 41883129 546688425 513809537 531150856 306175272 387117768 227086627 141109966 751390232 611889150 543538358 299200569 644716903 918048564 888852999 340160262 702167737 61630391 341729246 926128603 377160762 310665470 263272086 250233390 666536330 633684587 846511751 831786941 614509574 687496598 573753261 440304884 692800823 267822983 332094799 34489289 431985304 969361156 368626782 80720996…
Output: 386262499930

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
The segments at Caravanrest - MEDIUM Coding Problem | CodeTikki