CT56595

Dorian's Wild stretches

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Every season at the bamboo terraces of Verdantstep, someone must reconcile two mismatched ledgers. This year the task falls to Dorian, armed only with the stretches register. 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 <= 1129; 0 <= a[i] <= 1000000000.

Example 1:

Input: 642 163248137 692137758 611380828 596801157 809314946 167484329 397946506 413324579 635603712 392910652 711162443 653887295 406008994 141684010 229011657 643728411 973949652 847591377 37154238 539488935 904239150 408378225 254232590 488767239 29283944 652266024 536433031 524643915 365873904 973122096 638912426 111970568 350281308 667388111 272366466 37863275 511734861 313938890 502973267 838868779 209546858 476792062 305035887 100311284 407945683 839739199 804106243 690685410 506325913 951712540 812699306 789745893 203952612 80877158 774159937 598794918 806916086 371048170 427385517 799469090 164442200 679050881 430036560 791826989 841677249 96731159 339549321 967122549 589625659 196027690 767863021 115690369 628198936 720974291 465642706 428741425 774717621 616111329 161496389 587755550 2…
Output: 314043074301

Example 2:

Input: 370 166763629 983810405 427193809 323658318 712822441 325995339 46818803 146419456 247325136 92464528 683455775 522827719 383688783 41639244 436216370 562120482 357840318 921190747 902818303 766365288 925657646 9868798 637360141 946800787 978100150 826117173 95422092 293843375 666614958 875306112 915336417 164958253 701987370 901937032 185594536 393559510 965010056 841764614 41432182 883872450 470039933 703241948 955659103 371147165 576927387 948265013 439629102 76798248 804033903 66534316 333517776 998390781 761047611 539213971 78062980 455639876 527669187 612172787 555105426 428971721 717567381 279987587 363488754 696782148 777692679 845764725 522134940 373212383 135279870 540679746 442318823 498334699 994155377 513161530 428340038 454977233 91726001 615385537 183934755 392585850 5324014…
Output: 173754293696

Example 3:

Input: 263 166594653 446950036 374573848 563608521 954505783 820685580 202312919 149870234 221103723 612359144 939090661 656351875 20447508 695371234 271815512 594788344 98654983 690898928 656837311 644746480 447550208 517044426 750686628 586533783 667791454 576146221 955608275 697808061 416253181 147522678 618289712 244711213 639472038 654303294 521818940 327415684 226011417 309559706 795930237 415174186 417131226 140894051 300427481 131752123 468299332 209135446 967782652 788788413 913849152 793484643 976717742 50290692 61207539 567056348 716650782 975220685 856429615 670058235 96956823 986742256 260469132 909796450 434419920 213183091 349832266 643731849 633386717 810027667 186574686 974749973 657272472 690883604 906467016 487169978 428622026 810068428 203696479 859256130 401702131 317754519 7…
Output: 117052626761

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Dorian's Wild stretches - MEDIUM Coding Problem | CodeTikki