CT41137

The panels at Sandspire

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Morning light hits the desert outpost of Sandspire as Emir unrolls the day's manifest of panels. The tally will decide the next shipment. 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 <= 3873; 0 <= a[i] <= 1000.

Example 1:

Input: 1746 517 787 940 812 836 465 360 745 552 848 592 228 475 368 549 289 130 179 679 833 570 486 922 829 211 678 817 680 28 857 854 302 774 278 642 798 305 903 739 449 353 351 131 185 597 259 361 634 88 608 866 732 465 302 275 918 520 337 290 972 773 420 535 803 542 993 402 99 269 839 920 625 110 628 855 779 170 802 544 254 475 959 428 5 583 216 276 540 636 255 308 401 192 887 810 918 779 662 479 247 497 129 386 332 976 91 499 909 970 328 340 676 40 790 67 57 957 190 589 727 548 408 392 337 236 22 283 539 776 494 902 103 882 120 611 940 802 345 568 890 104 463 663 501 488 162 959 716 804 791 720 850 511 809 206 167 528 469 350 469 628 724 386 146 706 432 812 361 504 550 787 199 308 152 943 170 288 909 350 744 898 456 42 564 802 221 511 89 782 386 861 64 752 816 260 329 236 364 313 680 9 173 13…
Output: 861290

Example 2:

Input: 2145 276 163 229 649 968 450 600 620 88 582 284 920 490 515 94 288 771 886 971 213 262 189 889 792 410 423 254 513 298 220 35 909 653 75 231 854 815 779 498 108 716 130 224 509 218 545 580 736 835 329 851 932 202 169 687 553 602 855 615 535 549 457 46 185 225 683 539 1 165 261 607 633 413 462 993 61 537 520 225 689 677 145 995 931 901 59 205 198 831 350 33 584 627 905 784 2 761 151 423 976 443 572 212 805 932 577 411 255 906 614 527 0 166 642 116 461 114 651 932 914 463 563 481 697 460 433 860 569 294 601 759 683 923 535 105 942 112 965 384 922 488 723 328 359 339 284 0 558 427 627 156 819 816 178 636 277 360 227 832 312 210 741 237 519 395 43 151 506 174 509 752 306 686 651 53 216 830 499 961 536 648 764 771 450 730 7 750 331 926 185 224 149 568 531 609 390 218 320 951 467 156 522 40 847 …
Output: 1059214

Example 3:

Input: 1281 274 638 182 987 122 521 991 49 413 878 286 475 810 743 599 543 225 391 422 10 155 753 111 244 115 345 784 191 504 361 621 489 791 390 443 257 798 675 808 656 861 226 245 557 504 33 152 724 349 914 225 102 585 107 81 757 523 878 100 63 531 328 484 217 584 14 448 30 45 395 231 484 720 160 568 938 640 849 851 207 78 488 492 772 157 43 96 668 618 94 644 409 440 638 807 409 175 854 126 958 345 205 405 627 942 528 96 392 577 161 470 806 620 406 281 89 745 487 901 52 30 744 79 576 346 305 875 748 11 862 141 786 987 101 718 552 466 443 993 370 131 603 573 595 903 926 888 271 548 853 934 571 689 0 839 294 559 473 919 919 53 236 299 522 30 608 705 66 864 580 933 969 332 607 70 280 441 988 823 994 522 537 586 225 848 196 533 165 941 419 271 152 142 433 209 301 634 962 274 232 270 206 721 575 187…
Output: 627933

Constraints:

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

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