CT54809

Freya Counts the scrolls

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The council of the marble forum of Argentium pays by the answer, and Freya intends to earn it. First: the full register of scrolls. 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 <= 2536; 0 <= a[i] <= 1000000.

Example 1:

Input: 984 445232 232856 130052 898967 305240 828499 230573 633531 221339 105217 160645 775182 804926 458464 704733 361478 602083 480643 774317 177205 514697 178815 321792 214190 457352 278146 789131 75315 733234 639658 543607 133011 538546 570976 633116 203458 130088 427148 528852 144273 563035 310118 424829 769879 994771 811564 56203 633972 295920 156818 512925 718598 852686 877797 714550 248955 233936 568625 209260 408356 932303 291196 269988 115617 991718 84660 572445 86875 153625 973196 217746 754180 227313 621671 374684 414145 236559 750226 519733 219044 596357 843364 856398 299236 880261 878616 462844 625522 844430 738042 239568 163060 805094 3652 999621 274564 295372 197284 735987 579726 977395 567688 251601 991981 750896 734626 697161 338917 370225 249999 532114 381156 653853 237180 1883…
Output: 485328199

Example 2:

Input: 1713 325477 137345 318728 788137 56618 412231 565485 999356 519480 953779 179765 155201 623040 58478 158876 678375 44348 6413 20496 722445 337492 171529 868686 316914 657309 618988 311793 374106 17221 522604 539615 589047 814641 888667 488382 69526 837841 681444 629560 831982 429008 470478 535582 471776 564865 951152 612060 211010 908408 373440 443383 875822 69394 823781 182626 121740 966933 751368 431752 235357 382920 780766 314052 304309 782602 189550 984452 985198 431322 792880 81517 658415 466878 402424 915430 442539 140516 783812 233058 191495 267488 145165 585166 664164 182729 263596 724037 296181 29225 766378 519470 350092 832672 637399 151529 178727 796580 795040 336646 862598 642280 28420 658905 292729 17147 179215 399302 143580 381223 253233 364459 629668 204219 806430 299493 860…
Output: 860095874

Example 3:

Input: 778 449352 511251 564315 847273 102402 247513 648791 487056 275350 138777 388070 517476 99686 851026 532289 90950 139801 693282 639119 791668 999556 137826 434801 698669 393598 418222 694911 610543 9431 739145 633529 758176 382019 151769 400080 950559 501883 539871 587211 307911 46027 316906 810694 128919 830422 793348 547773 666580 496820 938826 795436 175790 280724 32204 741492 999453 674082 569684 147050 913213 717691 126032 263452 711764 535703 525544 371252 892845 88684 940250 192924 653746 290566 494859 376030 334951 424451 997375 312332 143082 230239 456547 158954 407569 353321 795002 448076 377985 153444 250046 226973 134742 359690 871076 534329 608661 196840 480189 514770 979366 113226 578084 600400 659797 70456 841749 877546 30766 140261 96614 684183 477437 822003 81229 323944 69…
Output: 367941175

Constraints:

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

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