CT61166

Lothar's Gilded stretches

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

Deep in the quays of Driftwood, Lothar studies rows of stretches 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 <= 1048; 0 <= a[i] <= 1000000000.

Example 1:

Input: 154 767345570 159606185 1665650 934548890 697454451 422230341 301642918 834958908 921114911 943604186 862441545 153714756 136488481 838036448 827274315 22344777 251808781 5658525 991791910 255928999 574534041 956840503 572558582 677931781 420763746 812519703 268864450 473867313 754758183 703248154 247869484 77165925 40249000 276536584 361854658 248134444 573683305 893301998 400794214 295144527 805802566 141516306 70835045 501749611 100866648 310447959 474763463 772145707 497917742 472828270 20083958 253998004 749504262 141985730 106074434 189612467 509022714 755291659 19047400 558884792 643188212 144073004 650987461 784083107 613757497 250875974 880615837 437915128 880010120 406325100 582485847 457993855 241927427 501706700 206263739 303487225 971480342 929033074 248297174 54543665 2712943…
Output: 73073547598

Example 2:

Input: 341 72899746 405898832 307118453 247943902 587961851 328355729 555664153 186722143 591843966 267830857 719733464 345969247 995382724 602902188 8826001 55990038 865031878 672775147 716811033 179291073 455446786 559664037 674342542 314597498 750012131 924667873 573890127 85107729 49912858 795007842 258223508 667053999 438013645 423560780 439709153 2693263 892991589 952848694 7344360 914300460 409135074 949716094 385007278 261694564 251211548 296649592 34345179 72021621 619002927 918396840 205809851 764613135 823235444 414340088 524129542 235088682 787859521 322837145 248006439 806287985 178458108 621000874 239382633 298543922 685341895 44235426 148197681 481892058 228548316 176861502 688449648 27109055 22938100 951817376 779849534 679840460 616657184 410622396 362822683 527861044 749126399 2…
Output: 167252745863

Example 3:

Input: 625 418361586 728260796 672777829 714505958 116762202 942868672 651088101 154444090 420786482 252539358 29322211 571710567 582782308 351901628 405640511 543429085 376494270 164399429 628762953 753169797 701545762 111796274 582282144 660262163 744620785 257220207 300040116 54305693 618290804 615228867 139856185 169009296 541713928 249960270 361419888 447060424 21483734 906294413 951584530 352901888 246797106 836208752 408207500 179465904 307144814 186038785 464220539 589410472 426366336 5086695 192199776 419345739 629338013 574559330 859272977 99313292 84198426 136226533 872308828 754004920 292646860 974461662 792485494 534330747 803038322 754490814 484361053 163604038 637195475 960678054 564865532 345431819 85129503 877265424 507477525 374622284 975233535 536842322 438449541 643038526 6294…
Output: 310425667806

Constraints:

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

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