CT40926

Opal's Ivory Ledger

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Opal inherited the cellar at the ferry landing of Crosswater along with its curious bookkeeping system for ribbons. Time to make sense of it. 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 <= 1818; 0 <= a[i] <= 1000000.

Example 1:

Input: 1296 638781 640740 505410 259730 435936 526484 459723 428406 259838 900519 867215 344986 180405 170480 242923 688012 401062 56303 739341 831825 668910 872466 843590 885769 85753 822234 19861 712413 61095 83634 901414 553047 913555 384477 647113 930746 670036 623420 178114 422401 930868 204389 944174 844963 239719 428191 303270 747819 295046 121173 15033 916268 188211 80495 665276 435195 200300 284505 376458 7046 202815 743378 331328 64323 403532 600696 498728 507631 750957 241198 752281 820066 544154 767560 225526 309813 842683 691147 856414 510951 86673 970410 128585 863016 766230 121480 999350 912347 595250 765747 508292 508379 418541 440989 912465 660003 67261 343166 259611 233953 608941 809930 246028 79084 558601 84340 15480 508206 426936 92234 68598 386318 635761 240867 178285 165729 …
Output: 640974126

Example 2:

Input: 333 729134 437304 175294 847980 811302 130684 411185 714264 686124 66288 415189 975051 41443 161160 631860 327321 856346 539164 884738 996321 985676 34532 126479 941863 711225 974861 994363 486394 709204 805368 614569 893849 671905 66371 44384 755313 24964 100348 793384 663513 73820 246483 51268 669373 271036 17992 623463 42191 925221 246966 213422 363322 942373 238060 259243 138656 515134 461556 317284 670004 793548 755156 579988 369772 497456 299045 142992 528832 930465 532608 74315 876952 888287 421196 543435 356916 878748 403588 612185 763180 271136 122272 950133 528326 524887 227633 852675 661431 116035 187341 735124 61529 255023 484706 651959 528899 121112 26644 86631 464729 974865 268479 547886 400110 903224 32024 136689 428881 420278 135283 578746 507122 384891 589263 203741 844531…
Output: 153564025

Example 3:

Input: 1350 822799 375881 955077 443242 219072 926441 181180 225807 710592 634780 905232 919815 908471 530120 168927 807977 68059 398760 274598 810449 741833 836394 449868 990202 434294 483265 206636 829005 641058 692232 272690 172734 169316 548689 919779 584190 779995 811798 60312 967355 874948 329046 659663 879827 990361 326250 604197 745354 763068 480643 419630 78393 249926 925134 157690 961215 551347 437203 631543 677284 634112 638455 235129 475993 90826 793980 590834 960770 400925 950498 412326 180030 561964 179308 595466 821202 105579 469202 138264 220140 54376 989331 369880 587380 62822 497363 711635 441167 120399 936015 205824 356197 932780 729833 289526 321972 472176 385302 472505 150406 508805 945673 197508 718176 602105 778073 910987 454143 190353 264775 945340 700817 899126 202104 656…
Output: 652320538

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Opal's Ivory Ledger - MEDIUM Coding Problem | CodeTikki