CT36490

Corwin Counts the scrolls

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

At the crystal caves of Luminar, Corwin records each scrolls in a worn leather ledger. The guild wants answers, not guesses. 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 <= 2462; 0 <= a[i] <= 1000000.

Example 1:

Input: 1240 571881 251145 404342 574241 496497 805880 566503 792438 436889 764125 343667 367238 685295 797100 442264 583205 392858 564397 627022 263090 467193 936459 541860 445299 308833 237340 139193 300674 751249 656572 489024 923159 350626 931999 647221 936975 250256 661075 975936 96304 224781 442628 505277 432972 853766 536062 567378 294362 524491 755893 965102 546825 646812 997768 7244 565323 461959 556660 954216 962774 408425 531483 735024 195951 847069 116773 544003 4930 541413 23664 763446 523019 415243 982784 484094 732434 182573 164009 396182 891214 595696 897430 310258 975159 354431 54451 561425 978818 605726 948768 35152 837429 233171 409997 566333 572328 521180 568951 413897 728150 491918 420607 932609 396935 305187 646279 839523 796690 262891 617396 298207 630440 939138 785971 99225…
Output: 622695806

Example 2:

Input: 963 727173 364102 808919 363914 919384 990938 731579 541331 587560 641066 418174 565588 171597 813650 760281 207636 702410 275161 318523 329837 543106 486425 974412 399523 306210 177283 233889 587469 119791 979059 729627 520099 787474 905290 615567 956200 371127 857102 617741 325425 277885 277829 598323 134155 6515 987229 599419 601086 135852 128081 101231 798167 664610 519858 986853 539450 30246 592913 499551 99590 597683 704455 311916 244789 936238 362985 393808 901425 211298 620302 297247 515037 605445 5975 129128 486134 399021 701380 100726 53826 34837 540971 934113 573369 76750 595456 20112 305700 485905 141874 530226 949140 432520 693366 452357 877382 229405 277070 456870 407909 632079 47066 564901 353207 949508 838864 851835 694150 651664 463025 753858 894059 332079 60731 161713 175…
Output: 470795602

Example 3:

Input: 502 12717 314902 159548 580321 117458 841780 866691 854868 617866 563483 677818 847919 994958 680732 28483 860266 682594 856072 721583 109763 465220 288114 6161 405687 657878 488023 499052 467008 361274 264819 828917 696530 699413 90955 378405 855240 129591 72997 629403 421197 324920 199687 960909 796859 75267 597052 817354 727713 167170 598477 645396 917632 411979 549750 382425 504413 550287 507527 122709 18544 529978 672034 112803 561901 791565 363176 580520 328707 29756 288725 393507 528447 79295 786394 524680 56526 792156 630616 285675 207226 151587 552266 232736 196827 258260 723979 271033 946580 619748 478853 586590 151838 318484 491069 381254 24021 32805 452919 865770 144319 819617 643791 682882 440916 584588 431018 549238 961219 788185 861804 749593 233737 475269 743981 91064 32974…
Output: 251574931

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Corwin Counts the scrolls - MEDIUM Coding Problem | CodeTikki