CT42851

The panels at Cinderline

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

It is audit day at the railway depot of Cinderline. Gita spreads the panels records across the table and picks up a sharp pencil. 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 <= 3036; 0 <= a[i] <= 1000.

Example 1:

Input: 1410 188 534 783 576 567 837 256 580 535 758 201 31 979 883 209 265 798 926 782 346 796 701 653 85 697 961 33 955 608 590 700 23 45 317 379 538 337 201 356 144 401 183 420 401 646 151 358 898 991 233 666 647 693 614 801 853 192 313 590 686 969 889 41 75 147 2 243 199 762 245 340 411 133 654 139 56 320 895 833 688 780 931 307 381 941 491 869 126 734 821 958 890 708 559 113 665 241 175 579 620 696 280 184 430 867 285 305 480 893 755 558 461 928 220 255 907 697 370 986 564 858 293 866 879 203 909 166 982 949 357 239 409 698 560 917 930 962 789 592 677 684 73 526 98 1 166 9 89 755 559 653 841 97 913 244 291 490 180 679 629 923 731 957 755 274 527 268 722 433 933 385 953 408 408 776 284 126 206 248 879 689 72 391 71 391 629 286 678 337 645 56 896 456 485 398 765 670 309 467 654 654 338 899 675 …
Output: 676444

Example 2:

Input: 1488 431 337 686 813 114 643 794 262 191 389 131 833 564 739 239 126 706 399 449 477 877 634 427 286 617 905 904 724 594 572 544 305 198 129 38 391 799 764 814 315 200 743 354 163 924 499 493 65 617 9 958 39 893 549 945 757 763 747 221 335 237 318 518 706 937 395 550 722 120 971 72 366 172 495 591 45 253 519 118 182 630 961 853 353 479 485 239 170 752 485 68 460 501 622 605 212 200 375 887 848 790 394 426 922 681 189 84 266 855 532 251 331 875 323 669 742 490 591 104 574 729 546 932 452 74 557 595 153 925 935 760 548 502 635 809 921 830 979 77 677 91 706 956 596 505 162 644 832 606 458 898 634 993 825 386 825 474 144 447 47 149 482 15 617 651 717 419 628 305 516 718 275 647 663 570 763 361 425 83 119 586 998 179 619 719 490 851 861 259 433 714 275 663 865 997 653 579 232 355 396 32 481 308…
Output: 734298

Example 3:

Input: 1853 752 573 110 683 751 24 733 801 312 77 52 659 351 39 355 968 598 4 359 986 956 166 591 914 709 591 346 833 846 203 603 934 480 409 945 97 127 715 239 654 46 307 702 187 348 691 986 613 953 629 598 683 96 459 526 603 287 956 44 559 168 464 969 417 811 99 277 922 23 634 234 391 584 862 284 219 751 917 766 18 778 800 31 229 547 119 929 839 966 159 521 595 882 444 236 323 930 404 864 545 405 264 575 449 3 157 784 397 696 741 747 432 643 303 247 574 775 693 317 327 488 357 522 655 947 808 310 964 296 4 273 141 344 668 33 911 596 320 770 657 675 738 177 575 969 166 20 542 392 754 421 750 757 978 751 329 593 132 135 809 954 93 336 622 167 187 122 801 52 12 592 490 539 416 189 170 611 315 844 865 991 41 686 328 27 504 157 967 488 740 653 330 545 621 663 489 645 903 157 671 525 305 521 665 466 …
Output: 911829

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
The panels at Cinderline - MEDIUM Coding Problem | CodeTikki