CT47160

Last segments of Indu

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Deep in the marble forum of Argentium, Indu studies rows of segments entries. One clean number will settle the guild's oldest argument. 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 <= 3653; 0 <= a[i] <= 1000.

Example 1:

Input: 3605 37 415 972 157 432 768 771 403 14 224 205 754 398 350 606 660 739 913 949 68 38 64 300 820 892 334 334 976 107 256 262 423 213 278 926 4 412 717 188 669 22 869 226 800 826 402 239 546 587 510 828 637 498 155 721 905 789 49 774 92 435 490 667 167 608 297 829 711 979 962 784 488 409 856 310 417 230 317 817 76 738 211 229 925 632 762 12 777 60 679 356 982 322 217 462 554 467 928 683 921 207 853 427 516 82 639 522 343 458 700 705 128 627 500 959 38 904 807 27 934 631 754 250 77 936 85 946 759 629 490 969 402 19 436 833 873 407 295 440 699 345 711 325 428 811 374 399 964 4 960 721 610 318 446 600 652 904 462 915 552 365 483 697 837 97 792 344 551 1 397 90 823 667 447 648 148 832 304 278 296 905 918 585 734 205 133 237 435 456 724 167 40 393 29 219 911 936 843 377 344 184 931 84 476 910 591…
Output: 1788176

Example 2:

Input: 186 678 885 980 244 965 126 166 834 218 886 924 919 238 301 226 288 181 714 173 830 179 948 675 243 28 111 527 654 45 152 56 963 538 575 653 660 339 30 708 733 129 795 323 880 350 598 998 460 773 837 363 811 549 174 912 96 207 488 281 497 862 398 131 785 224 148 233 150 568 783 704 390 99 368 270 453 21 358 857 783 779 105 899 472 154 110 326 409 548 227 358 729 711 293 569 419 739 474 814 116 82 853 348 730 237 392 372 675 776 788 325 6 610 920 353 282 586 533 466 696 95 832 789 844 245 950 713 384 83 502 360 701 673 647 752 790 447 351 926 981 128 566 610 2 702 208 784 615 8 996 485 590 702 791 296 303 240 181 480 154 898 635 780 801 940 744 714 504 442 590 912 444 705 903 185 162 33 138 488 89 280 653 578 605 736 574
Output: 85801

Example 3:

Input: 309 822 133 338 314 594 41 942 748 867 362 706 238 331 292 785 581 409 739 43 950 847 142 274 193 430 596 366 340 50 638 731 198 38 115 501 84 823 59 687 204 538 683 471 380 774 965 866 797 892 835 14 536 342 139 424 545 99 228 527 52 199 925 489 269 152 740 575 554 887 623 511 131 65 876 389 45 562 430 145 106 440 145 899 676 312 754 240 139 456 886 596 913 855 679 712 838 46 333 794 262 859 215 960 925 828 652 440 113 109 863 718 62 464 776 696 933 253 649 548 692 46 691 6 380 2 614 251 739 140 73 284 352 458 81 374 745 286 744 322 258 369 86 232 962 930 773 358 480 918 772 32 873 96 380 184 646 594 416 32 651 601 206 177 405 914 366 376 280 671 3 64 789 565 747 463 316 493 243 321 79 431 413 280 352 448 883 435 922 438 619 616 665 382 230 787 843 845 217 428 182 871 812 860 62 10 6 329 …
Output: 144989

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Last segments of Indu - MEDIUM Coding Problem | CodeTikki