CT58153

The ribbons at Briarthorn

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

At the forest village of Briarthorn, Ishaan records each ribbons in a worn leather ledger. The guild wants answers, not guesses. 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 <= 1389; 0 <= a[i] <= 1000.

Example 1:

Input: 1136 360 449 205 457 798 236 938 748 42 195 109 541 548 532 812 320 525 127 499 805 939 813 607 97 268 42 965 800 137 894 318 769 218 161 100 127 195 213 942 833 209 230 759 786 159 406 807 361 546 471 321 342 808 745 981 295 89 383 664 88 222 576 404 813 680 818 11 436 659 52 388 28 648 660 905 798 204 915 714 842 78 835 145 856 921 93 488 886 605 266 541 398 452 947 394 740 458 119 534 497 785 489 268 487 997 978 674 766 869 591 165 376 357 984 182 699 465 335 451 95 504 308 901 891 144 721 231 526 570 160 41 107 531 668 324 547 740 170 497 418 551 859 229 101 441 412 121 60 219 384 27 408 799 211 71 152 279 670 146 919 14 455 151 645 531 472 641 770 771 424 332 325 127 51 395 109 696 132 2 644 492 794 969 325 724 762 656 588 178 927 401 69 59 149 15 494 195 874 145 282 404 808 644 780 6…
Output: 555915

Example 2:

Input: 573 822 729 754 533 715 380 580 240 818 359 790 652 528 226 974 112 885 838 939 991 601 184 719 850 346 674 961 204 285 654 453 481 817 195 786 2 278 14 853 276 960 925 433 780 545 819 273 111 520 398 11 60 856 277 353 525 762 889 766 334 894 550 347 898 694 860 791 772 969 919 48 978 273 317 750 743 396 940 236 742 668 843 714 492 320 110 457 960 699 425 505 144 291 961 162 718 185 781 831 490 27 295 524 994 6 647 29 962 173 161 639 573 770 770 456 83 227 378 517 93 911 82 390 18 568 86 564 207 624 128 231 782 730 667 194 518 540 961 900 984 865 895 382 532 804 809 181 445 752 154 315 286 183 655 584 987 299 362 893 206 863 907 555 818 315 831 857 691 426 155 122 113 269 294 410 711 785 999 913 441 729 249 15 302 617 587 26 992 184 792 317 6 45 107 488 529 642 344 276 533 213 876 794 30 3…
Output: 276673

Example 3:

Input: 203 920 792 273 655 953 581 442 117 149 82 250 851 709 317 884 697 78 327 44 351 305 587 225 548 512 168 389 373 385 17 13 661 393 539 757 750 137 642 312 820 504 509 966 567 382 492 876 283 730 101 408 363 250 963 386 714 74 675 55 992 483 402 441 856 415 267 129 0 164 974 943 6 673 28 907 967 469 435 58 721 962 961 312 193 619 947 961 983 954 191 477 64 787 116 890 656 937 627 903 182 778 441 789 514 341 94 624 429 762 771 868 953 659 668 414 768 780 208 946 495 127 833 801 107 650 213 716 408 569 63 191 248 419 754 201 566 763 909 173 81 706 433 540 385 805 463 692 599 73 762 207 884 354 378 405 534 172 213 585 7 81 25 522 478 330 116 904 810 900 383 280 503 653 235 911 613 774 951 123 966 856 84 717 773 502 529 116 694 141 157 19 653 785 765 134 72 263 861 156 516 613 893 368
Output: 91847

Constraints:

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

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