CT49955

The Nacre Bay Rain Ledgers

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Morning light hits the pearl fisheries of Nacre Bay as Quartermaster unrolls the day's manifest of scrolls. 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 <= 2357; 0 <= a[i] <= 1000.

Example 1:

Input: 873 469 360 8 952 327 771 3 462 575 410 455 678 759 899 608 232 920 247 765 650 678 481 33 894 365 982 763 965 855 706 967 124 475 730 216 383 719 100 382 310 21 709 549 872 374 348 526 857 317 115 868 248 621 857 539 917 87 207 19 906 132 735 152 917 71 120 286 571 360 68 307 276 261 773 15 832 398 280 375 286 85 180 308 724 45 733 62 773 6 688 457 159 52 209 261 238 777 981 821 394 454 982 656 586 910 165 379 148 85 155 954 556 847 856 836 432 707 372 517 866 888 469 880 523 51 142 729 913 973 879 79 314 479 360 248 730 943 488 897 202 590 993 865 73 410 817 471 370 555 860 196 503 647 578 170 833 380 55 911 447 35 252 42 196 146 202 494 280 378 720 419 200 863 960 629 482 755 463 363 399 863 62 184 803 443 196 187 448 299 182 705 426 715 183 639 592 580 345 931 54 453 448 175 799 431 35…
Output: 433722

Example 2:

Input: 515 322 774 259 930 40 166 500 735 983 277 979 501 631 517 247 275 891 837 426 286 945 592 935 604 638 706 4 63 79 825 713 672 237 564 810 67 439 846 290 466 99 681 291 232 391 335 961 100 902 835 717 102 185 622 841 934 773 625 756 648 256 177 129 520 521 570 218 575 284 309 916 764 779 27 589 943 891 185 769 224 656 605 271 906 834 320 738 166 440 821 60 134 723 550 134 877 978 70 285 763 351 495 730 913 857 575 102 704 960 124 750 292 927 950 45 266 426 176 444 136 398 141 732 407 93 505 830 966 319 362 518 735 493 228 968 134 736 922 370 645 433 320 768 530 559 889 737 0 187 613 672 327 725 616 10 735 748 451 491 544 474 109 976 954 823 973 742 966 41 289 810 755 676 595 205 376 398 293 472 456 349 255 435 234 483 799 865 902 238 490 865 371 786 915 81 906 497 859 565 911 202 395 535 5…
Output: 237367

Example 3:

Input: 715 201 282 739 286 344 387 400 35 256 598 222 761 459 878 447 913 789 632 365 982 398 840 180 691 282 600 335 495 94 515 298 6 974 159 313 752 287 456 394 314 913 51 95 345 729 68 804 262 635 381 416 852 670 5 366 700 55 317 275 631 835 331 967 853 280 440 400 829 65 560 620 955 965 450 554 939 236 45 844 609 474 623 731 396 298 98 256 926 470 986 233 254 564 829 421 694 981 929 888 728 274 912 357 328 581 575 674 840 859 7 733 13 766 68 408 9 70 164 621 932 848 169 654 994 143 172 790 518 891 687 358 130 726 353 56 542 466 503 246 264 572 284 314 964 296 272 47 565 390 99 366 531 828 423 154 444 557 686 467 950 840 414 421 555 66 70 7 891 590 277 324 85 604 690 354 166 214 890 716 767 475 449 74 574 501 704 472 598 416 44 605 436 444 608 338 313 398 349 998 130 399 230 906 720 45 374 929…
Output: 340270

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
The Nacre Bay Rain Ledgers - MEDIUM Coding Problem | CodeTikki