CT46892

The Silver segments of Nila

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

In the kelp forests of Tangledeep, Nila the surveyor keeps careful count of the segments. Track the breeding season, every figure matters. 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 <= 1275; 0 <= a[i] <= 1000.

Example 1:

Input: 1064 7 903 502 910 8 810 204 799 151 376 906 976 753 52 102 604 408 246 671 365 744 282 223 130 369 713 800 92 766 383 725 241 103 351 560 63 460 504 218 183 962 932 305 32 610 320 650 773 60 231 811 813 793 63 99 790 401 3 146 980 165 783 251 174 886 327 847 907 63 216 539 714 252 699 172 509 613 616 859 681 154 407 309 978 951 902 800 906 331 454 589 107 236 232 551 71 539 726 797 83 320 899 328 255 362 200 453 894 361 847 93 95 588 3 576 775 313 933 241 256 408 343 837 619 733 786 668 197 408 447 102 344 708 679 84 805 433 720 542 99 233 638 268 374 611 157 500 234 819 767 645 893 160 255 254 416 353 660 521 823 935 109 899 552 415 229 868 150 802 321 609 757 40 579 370 299 238 677 245 243 944 100 811 108 419 942 438 688 88 993 416 663 629 769 960 243 940 318 87 835 146 3 782 732 177 58…
Output: 531200

Example 2:

Input: 1167 436 739 595 811 460 121 329 511 428 528 396 484 622 151 216 164 123 560 753 499 707 413 831 303 606 95 647 452 869 998 214 280 696 641 317 602 647 68 477 719 776 870 984 57 971 311 789 851 870 715 234 395 908 922 262 120 849 776 415 97 133 614 520 892 538 521 179 499 540 608 238 572 912 229 356 593 243 209 837 925 959 800 179 952 135 288 634 40 155 77 320 193 337 755 504 523 695 159 488 773 528 721 995 358 465 921 6 658 467 953 422 834 948 699 103 306 364 617 493 291 555 576 494 153 641 816 156 126 921 28 507 553 41 704 53 937 663 879 656 808 615 288 501 927 756 918 522 371 969 526 267 906 757 548 397 120 70 921 329 500 417 675 63 742 748 723 401 622 283 822 591 177 389 197 9 29 203 130 960 589 926 292 224 989 369 526 635 832 770 623 326 676 833 964 519 164 725 281 408 112 9 165 11 42…
Output: 564798

Example 3:

Input: 127 957 319 70 564 669 689 904 566 162 316 23 384 930 348 704 918 348 839 88 312 448 744 869 981 484 142 255 454 777 220 395 318 981 544 11 188 522 730 618 783 561 209 813 8 56 296 965 600 487 283 262 792 303 471 416 159 455 98 149 669 813 950 538 913 376 469 123 598 652 651 818 354 312 588 516 834 911 977 559 288 42 880 472 902 551 6 332 513 145 906 981 648 203 79 523 926 494 642 765 653 823 296 742 536 249 200 477 714 921 165 488 32 490 463 402 367 469 724 979 873 263 960 901 494 255 870 650
Output: 56840

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
The Silver segments of Nila - MEDIUM Coding Problem | CodeTikki