CT62988

Varun's stretches Rain Ledgers

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

It is audit day at the desert outpost of Sandspire. Varun spreads the stretches records across the table and picks up a sharp pencil. 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 <= 2529; 0 <= a[i] <= 1000.

Example 1:

Input: 1934 575 378 580 348 111 956 439 846 942 963 617 146 616 799 423 383 27 222 802 415 244 482 558 658 7 336 91 234 733 566 311 84 960 456 488 446 417 410 930 364 718 700 906 375 323 596 905 927 282 553 361 100 20 280 248 558 179 557 859 381 641 746 836 512 835 643 474 105 608 558 107 946 199 845 921 285 798 441 825 663 967 411 213 584 487 69 741 761 227 688 403 253 839 248 200 7 801 557 484 221 985 885 80 430 466 865 379 926 710 260 870 283 64 69 740 414 75 543 671 660 935 130 643 318 890 482 197 553 886 162 910 901 638 992 449 172 999 625 193 276 662 46 527 38 128 12 854 357 28 368 570 589 304 284 919 984 632 724 418 908 976 101 706 67 68 189 66 220 774 90 137 30 724 906 687 393 914 1000 318 375 763 724 820 142 997 216 777 706 310 973 397 188 368 483 239 545 986 676 703 658 564 975 755 123 …
Output: 950322

Example 2:

Input: 2215 539 94 337 71 678 318 989 653 251 240 700 600 695 894 880 297 735 556 56 309 246 277 353 681 926 894 248 945 199 541 513 134 722 804 18 500 60 601 100 843 727 509 91 322 385 212 87 192 214 261 482 727 502 427 776 624 1000 910 49 806 305 267 333 980 901 833 691 384 294 979 602 275 389 484 569 241 660 604 844 857 776 386 834 973 385 498 922 442 756 549 266 513 4 118 651 349 391 303 263 402 619 669 390 552 97 384 491 837 189 956 779 114 825 373 762 851 420 56 476 233 160 277 491 872 37 820 536 937 11 10 960 523 599 50 751 781 203 64 195 257 699 603 694 857 347 153 163 531 453 515 492 93 90 597 681 444 70 792 541 749 441 965 596 920 845 29 703 35 665 681 514 613 187 562 276 385 559 769 449 636 743 742 509 234 548 335 282 954 129 816 472 360 309 324 73 838 896 707 561 895 443 833 993 6 235…
Output: 1108809

Example 3:

Input: 2406 948 725 341 86 551 892 924 343 237 964 588 148 445 123 355 170 726 490 539 308 888 507 192 706 276 589 957 291 121 489 895 910 799 964 519 257 120 554 998 56 121 582 29 355 798 267 224 672 101 513 323 860 520 245 814 925 733 580 454 144 835 640 908 296 116 557 693 446 875 896 559 583 321 380 337 729 541 180 35 741 803 179 355 543 755 932 146 30 441 949 223 243 764 923 913 708 614 344 807 743 303 239 345 673 419 914 350 548 263 741 532 973 368 453 523 846 333 761 662 158 208 167 876 142 267 957 758 511 492 403 92 77 380 949 887 597 784 278 594 464 943 329 341 325 605 351 337 952 652 840 248 692 665 177 33 571 367 184 781 261 838 563 893 320 871 843 407 172 991 39 775 494 507 608 659 273 203 278 305 571 415 810 413 134 207 639 39 352 917 392 263 453 480 515 710 352 846 146 701 758 624 7…
Output: 1172742

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Varun's stretches Rain Ledgers - MEDIUM Coding Problem | CodeTikki