CT63850

The Rain Ledgers of Luminar

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

Deep in the crystal caves of Luminar, Tanya studies rows of segments 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 <= 1990; 0 <= a[i] <= 1000000000.

Example 1:

Input: 1485 518348696 787048081 11846920 991613583 560677505 666481764 49977422 965360315 819133079 212503522 91209262 560863242 70857531 439195008 729119645 236009472 123473096 145497035 534779494 867430154 244330418 63433488 767790422 383910168 314869529 98542575 766203434 869621064 220926331 644073927 616902460 643927957 875729312 36205928 589692832 70942181 26850918 146748477 507282619 337932423 835814357 195342658 774936798 464244615 515489882 80051234 31508738 102554106 684595994 147507591 24682305 205161509 880169247 497364088 275504707 242209888 937280738 318690215 320426421 674931906 464224548 300060490 629160830 86844422 562315619 704858251 66715226 994377252 787719937 657823497 594924591 922355310 537093078 106015120 699061488 958545478 591837242 92061161 320375657 938223676 241054225 …
Output: 738288204460

Example 2:

Input: 1399 213886807 31051357 101583122 777502890 13384764 768917626 500242444 316136760 639313832 724872799 432107218 621958916 180700217 629665323 718534797 909015818 815537434 99522801 124957885 896953916 268737077 818077344 831596477 132638187 620234546 572113900 218660279 932301083 873622534 732049169 167069219 282967787 188209963 34962066 819360042 398048920 235874306 103793720 394567151 779701118 451020885 446916531 593267221 648401529 902508143 115025749 29042774 100456942 307147619 495476505 853087410 566999902 343959909 88628664 270073573 313600060 426220572 334142073 680719363 85249882 750010726 521319957 107645796 667020768 574270747 529716824 555716898 800347658 682674455 513723979 72224189 746234097 398309797 903890536 473313723 354076736 784665503 631945727 694242901 892819967 368…
Output: 683969705597

Example 3:

Input: 255 848457281 262104388 200629429 481828967 937176280 923512033 186384952 230314843 408994763 131370319 883856790 626780831 70066922 441376346 305022704 496089301 910161836 861549503 969192525 677546670 690794958 58917033 521113093 796830283 883348948 940922106 461144980 635256090 780766342 756648141 736684475 825782769 196772481 451656144 604761116 32869080 492733789 290934008 644934459 686108299 8960214 876689001 46173988 820014020 440454120 74110206 709493737 770827140 892162310 520001749 342539294 313769546 626302084 369550348 111119246 118919862 456452916 336453500 238273638 592203305 170972708 820470267 66101189 23306239 730483530 685802140 631873595 663767942 138262038 878189160 42406383 762344901 712574202 431809051 854939498 472215185 73812628 22719102 644438113 746690838 26281069…
Output: 119265708331

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
The Rain Ledgers of Luminar - MEDIUM Coding Problem | CodeTikki