CT57713

The stretches Rain Ledgers Puzzle

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

Before the gates of the mangrove channels of Rootwater close for winter, Kate must finish the stretches ledger - one figure at a time. 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 <= 1962; 0 <= a[i] <= 1000.

Example 1:

Input: 828 398 769 530 774 698 733 788 867 472 281 973 131 911 544 406 764 612 940 450 663 737 163 245 240 626 754 856 354 486 761 637 414 79 814 84 338 331 119 508 918 936 118 431 287 758 919 625 275 851 83 755 925 864 818 28 225 977 313 755 706 558 400 570 984 823 295 330 183 609 897 417 420 533 66 227 322 713 138 286 298 257 815 108 526 155 511 469 204 975 342 140 168 382 926 788 639 537 596 907 667 761 843 663 307 955 129 648 623 48 938 531 945 266 680 87 246 68 902 15 762 171 673 376 787 26 352 475 610 480 412 109 569 862 67 898 426 622 85 463 38 797 221 523 449 55 657 427 657 63 690 895 391 343 211 842 90 712 136 345 819 388 427 925 131 985 402 13 759 874 877 48 491 783 117 186 789 843 254 207 92 267 648 503 595 74 946 633 508 495 694 120 323 508 8 236 129 308 568 311 390 801 77 589 209 99 …
Output: 406496

Example 2:

Input: 1697 851 201 14 418 391 53 465 68 560 543 416 306 588 256 202 588 858 830 172 959 699 156 249 89 654 386 906 762 435 658 326 514 618 842 469 918 272 98 642 737 126 667 129 232 291 98 44 268 112 712 268 232 471 801 527 442 837 823 589 316 909 636 765 174 178 120 64 690 726 100 627 269 228 751 300 887 531 454 968 730 516 300 167 67 832 925 915 920 885 954 826 740 790 117 985 732 299 555 374 774 936 970 934 703 242 667 589 915 143 720 227 153 965 990 712 321 960 324 335 566 611 40 297 170 131 783 79 430 745 259 954 199 400 363 688 174 865 42 656 760 378 828 968 608 423 6 22 395 231 787 125 697 300 688 182 983 472 372 182 332 196 547 517 452 172 668 721 738 243 341 436 411 343 535 488 510 683 774 739 713 491 22 138 480 709 990 159 367 973 898 842 726 557 366 851 374 415 638 866 600 493 45 446 …
Output: 834153

Example 3:

Input: 1243 460 368 563 545 48 984 738 207 359 264 555 823 917 39 520 185 334 448 246 664 107 965 74 929 849 153 396 606 837 407 974 973 427 568 873 218 147 692 366 408 699 886 958 880 732 559 526 121 241 73 386 416 198 131 858 582 723 182 434 800 597 360 995 769 48 828 606 616 61 748 28 329 546 779 800 220 298 37 830 335 858 79 402 76 975 880 515 568 955 581 944 302 806 823 299 447 716 951 957 243 927 896 632 235 62 897 753 468 339 41 836 498 864 608 186 503 280 711 887 349 537 251 935 357 118 825 109 91 272 832 965 278 320 175 603 909 835 484 898 269 260 865 702 211 195 796 98 877 393 447 314 6 287 64 246 1000 297 592 991 382 152 27 995 946 622 680 348 863 339 881 59 272 791 747 7 601 922 330 96 569 280 653 296 732 377 954 984 264 791 259 28 100 547 921 97 628 417 832 571 70 623 484 200 384 545…
Output: 610068

Constraints:

1 <= n <= 1962; 0 <= a[i] <= 1000.

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