CT44348

Lakshya's panels Rain Ledgers

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The council of the cedar groves of Balmcrest pays by the answer, and Lakshya intends to earn it. First: the full register of panels. 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 <= 1133; 0 <= a[i] <= 1000000.

Example 1:

Input: 311 60981 61271 573980 302914 611132 448896 335223 419045 413687 321216 116993 965617 290734 420196 470806 234232 300829 643569 323793 180218 218035 726993 996036 837258 818077 399277 668356 371249 615977 669948 996018 953071 266685 632894 416044 119974 388783 841290 962167 943328 889239 744679 161313 449180 805678 919370 122491 965895 789852 474382 205311 596538 219339 409898 354327 269231 527303 675202 821593 947614 133804 400035 468131 555459 561238 454787 544614 375290 996457 71373 382517 654867 495105 254769 901716 678199 697156 571562 91146 222714 598761 967539 884658 678772 219468 182777 342489 40725 652074 805646 811367 786578 327262 628661 145768 501605 948051 256552 391768 782886 509029 945576 416121 789663 298817 159744 18534 387121 316439 37961 138525 358969 32500 432023 12508 …
Output: 132610197

Example 2:

Input: 1045 585561 556058 69820 938176 780794 259896 710668 525343 358612 618610 793546 749924 686262 960836 296523 3886 576986 26955 623791 987686 177198 239456 101676 218314 720998 646777 718048 508318 272 552393 41772 631968 814768 910802 668692 780624 294863 650913 762167 343255 299483 98308 772690 861919 626920 401260 734390 155778 580694 464611 199497 652553 744694 871149 100871 439718 182921 295283 787009 424137 195500 228946 225611 998606 736831 800488 150115 12235 728269 302338 263288 102682 117845 73699 940696 504734 94035 244194 561136 995281 61397 79771 998838 786224 849790 810127 605227 693676 805167 210685 665366 610816 677637 451410 716629 858748 308385 7342 309952 566612 442830 138104 875515 768472 796064 453099 397480 594902 587776 847695 301588 690833 993127 111216 598019 406471…
Output: 496573963

Example 3:

Input: 97 853430 363006 590664 514960 213643 509182 483422 589011 66598 291793 661706 548587 629191 453390 435726 298243 55206 420364 580466 55455 832954 611578 68073 895851 372734 463185 322349 983937 871649 302414 181306 687502 277998 243404 673939 855567 323908 385670 657586 563044 430523 871984 933467 404466 327184 403101 922844 851147 538232 270113 127468 194082 587516 64882 239190 764832 75577 789465 178536 89583 543782 446750 612073 361391 404053 782799 194155 884742 28013 716330 462774 372380 469680 532983 161749 635636 529024 817746 746464 598205 129830 490229 904560 517469 198896 953383 73642 343327 879856 932668 258848 850874 435962 978522 215617 818149 631099
Output: 42879537

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.