CT56796

Jessa and the Rain Ledgers

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Jessa found an old ledger of panels in the kiln attic at the bamboo terraces of Verdantstep. The margin notes pose a precise question. 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 <= 1816; 0 <= a[i] <= 1000000.

Example 1:

Input: 386 337900 100609 191140 523076 485253 518947 153898 4098 169782 349647 860051 432167 112161 13321 160010 953284 571675 538991 807760 735929 317895 714596 798052 829419 913717 297859 417147 784559 204836 37509 348375 316486 89754 858013 420032 596078 67021 59224 991554 467695 125962 550106 530938 94510 293174 73586 805304 227953 210912 239611 622085 623914 454689 199084 220994 690905 4592 671403 702087 223931 180741 857660 553308 467585 300856 237254 73764 765496 74844 950950 502481 454012 694121 929210 174934 307624 356602 375237 280112 817197 159227 48369 174282 858291 604321 304111 717397 690919 191524 729812 18359 202039 715545 492570 504757 169009 870914 98178 270102 937751 731677 894643 186843 226913 187298 217842 763786 409574 733056 337073 361723 426779 112842 773889 780410 988238 …
Output: 188750194

Example 2:

Input: 1348 887541 610208 865876 430791 286572 970128 928647 144841 778832 323983 652277 513936 698111 637506 873130 716954 54262 981201 401996 215179 533436 221204 726409 259661 922927 947148 455224 373947 389694 803132 710039 407587 597330 747226 346284 817348 16297 173828 308447 553668 398469 193579 330836 302604 810090 852548 526673 173559 196421 922114 644370 219329 305483 231523 52630 370165 702898 536704 236750 217730 617698 520473 318800 861142 430784 526391 69038 162423 656970 455416 92119 768181 285524 528216 323063 478727 108983 739219 400581 158522 929520 549972 325636 146285 509514 255885 846398 917831 967530 286788 767947 496977 846035 820167 994902 69087 88354 647609 158042 832586 476965 84457 583374 187836 277643 29766 571584 482697 918904 620050 298936 156647 485637 663643 585040…
Output: 665260274

Example 3:

Input: 114 957137 530392 365277 175738 950689 267218 903370 28463 867156 504446 987320 858422 728192 210150 378505 255275 777580 959039 523133 909439 784995 941103 784690 408718 918031 253092 621958 669788 855973 903061 853273 131168 612356 242703 35723 54758 985676 572650 23264 421200 517910 175468 260249 574396 624603 830441 224351 977902 241769 373686 934569 57276 532128 106311 782325 343294 31537 823939 979663 348746 321365 917421 872615 213120 895338 708077 278468 827394 430495 938996 656283 2049 955439 341522 358493 159421 580535 806961 739699 190743 232557 105405 33378 138315 647988 706555 714188 361866 934629 478616 170822 681733 313217 258858 990727 873398 81871 860916 653412 657416 998022 426551 681197 919332 59654 634761 474293 515568 387463 756382 405189 821947 880620 216163
Output: 48129246

Constraints:

1 <= n <= 1816; 0 <= a[i] <= 1000000.

Loading...
Test Cases:No test cases
No test cases available.
Jessa and the Rain Ledgers - MEDIUM Coding Problem | CodeTikki