CT65181

Odin's ribbons Rain Ledgers

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

Deep in the floating docks of Skyharbor, Odin 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 <= 2806; 0 <= a[i] <= 1000000000.

Example 1:

Input: 34 596633088 333042649 563949698 682263834 818681968 408302328 423032061 484055393 505700609 296205821 275288089 544324429 800068949 44513942 122087356 610214766 143246825 758030842 380614721 509439934 409243189 175005004 776645687 479387729 706172533 507047339 69043144 329560074 700630964 201445881 798112648 673191466 484873404 175366160
Output: 9605432828

Example 2:

Input: 2628 768584888 830097632 392455143 600989496 429884027 242348675 514540047 555027707 861409514 130720788 95907439 546382536 223624557 580327883 480677703 820599345 72267526 944035141 72936943 752825571 115246640 860195450 535842845 918032995 86881521 930221093 460212922 811784549 67345146 723465207 54962865 917038231 393630454 623335152 826145544 239516457 738843836 312743129 499601848 627719080 346858745 554798798 548340557 876108876 725696708 805995663 228035730 848917513 586658425 870551474 393978804 681786904 719539558 215996293 500224529 195423505 68138400 860022581 97022247 26737442 208256927 704872111 71195691 731247902 945023934 422660294 871503500 296920545 567307813 553609726 729937025 920846763 688007557 259440500 382972904 314905776 826981240 558259183 86775914 944506945 510963…
Output: 1315143470552

Example 3:

Input: 1392 206441839 532876504 577916383 321878713 36262453 777258366 203935895 47652311 336265076 428167626 258713916 793396811 483298973 115103686 202143548 982706798 514379012 706275193 380309915 381780296 44704478 879320970 41399732 668441021 592471247 817528281 184943037 252381002 194068063 39096907 611679945 886035048 763484245 582126496 950297739 407471719 631049624 153971602 447158855 597442390 383919835 359933671 261419802 319813702 728667671 187501506 77999155 201115820 425599577 820104531 831819494 10398954 670158380 461838854 17003460 93101921 258035824 186676443 119307283 563660717 540438856 821995109 201291486 59693723 251610646 39476102 365344300 564936528 866706281 357436156 454441368 620505398 211375019 273061823 354620710 736696833 496802074 444348143 144496625 179705813 365924…
Output: 680404034846

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Odin's ribbons Rain Ledgers - MEDIUM Coding Problem | CodeTikki