CT43502

Brevin's Honeyed ribbons

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The harbor bell rings at the heron rookery of Longlegs; Brevin weighs the day's ribbons manifests and starts the calculations. 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 <= 2706; 0 <= a[i] <= 1000.

Example 1:

Input: 397 95 750 539 636 593 526 606 756 259 975 362 386 51 890 378 612 757 117 441 745 460 180 419 496 694 499 544 199 781 463 28 772 356 947 171 912 660 992 479 606 176 925 734 102 991 528 96 401 787 619 503 690 140 616 361 683 855 694 514 845 762 560 800 2 646 420 429 589 715 386 413 331 144 451 720 419 423 495 392 949 547 7 335 391 431 134 865 188 66 210 988 945 299 774 382 184 73 196 816 774 999 225 466 240 81 418 317 139 743 227 282 555 415 660 325 826 101 933 864 238 411 317 299 677 504 640 182 192 128 293 769 209 548 680 61 477 472 804 101 546 971 923 169 790 773 376 204 791 626 85 937 268 331 538 140 682 976 699 288 828 943 834 642 554 957 303 828 691 853 645 174 768 349 498 521 832 514 876 450 872 409 892 354 812 315 783 96 742 343 713 698 345 657 905 973 187 281 592 552 629 609 241 97…
Output: 188022

Example 2:

Input: 2043 328 710 245 297 496 164 636 777 978 583 235 626 837 438 592 5 492 448 257 461 58 298 726 159 658 818 71 932 625 522 937 310 856 473 251 125 574 390 99 804 17 893 67 16 719 474 985 147 420 433 903 248 291 889 358 882 365 914 910 325 170 430 824 338 872 306 954 365 84 495 297 357 792 353 335 16 347 675 556 666 843 533 259 326 267 695 393 384 489 447 140 145 353 7 915 286 605 537 106 644 761 548 947 316 433 420 675 348 539 539 798 591 470 137 920 821 912 317 647 660 560 317 951 705 210 585 716 424 12 37 537 275 678 281 884 426 748 981 746 656 420 109 426 875 428 394 593 809 120 209 488 936 312 345 250 712 200 350 400 674 888 922 696 984 757 106 775 552 163 620 672 249 276 246 371 695 787 987 839 391 557 43 115 374 355 953 813 397 998 553 664 944 559 543 355 452 591 228 438 786 901 506 78…
Output: 998900

Example 3:

Input: 1404 285 856 141 513 409 140 927 824 730 873 744 289 443 726 283 178 899 397 658 639 439 944 768 840 33 520 386 801 163 933 990 74 883 580 674 294 7 518 521 185 40 863 685 274 966 102 419 3 341 867 294 330 298 858 940 154 601 918 660 460 365 739 910 670 322 11 36 810 659 113 92 345 917 75 257 910 741 450 609 542 459 151 284 510 120 110 371 47 109 465 916 64 519 242 610 49 117 376 155 564 837 95 798 881 820 485 938 638 503 562 378 498 368 206 938 896 641 805 948 14 383 362 413 744 340 430 859 367 363 212 93 11 908 530 601 669 919 182 834 335 450 185 913 429 856 15 554 390 180 18 977 831 569 803 305 369 978 898 699 488 161 924 672 402 568 766 8 637 306 622 77 570 108 953 825 872 114 346 945 152 939 340 896 193 677 398 789 701 964 786 572 445 351 441 35 128 415 894 860 885 175 941 416 989 615…
Output: 697112

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Brevin's Honeyed ribbons - MEDIUM Coding Problem | CodeTikki