CT63916

The Rain Ledgers at Thornveld

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

Every season at the acacia flats of Thornveld, someone must price the new merchandise line. This year the task falls to Surveyor, armed only with the stretches register. 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 <= 1449; 0 <= a[i] <= 1000.

Example 1:

Input: 984 641 640 614 513 241 222 949 845 373 56 278 109 179 30 665 328 966 662 79 896 887 256 200 826 557 80 324 566 760 132 654 489 959 1 357 47 26 600 464 973 491 167 429 155 272 972 75 566 911 982 962 82 75 404 429 77 188 836 496 940 476 339 480 508 456 176 16 151 804 142 158 814 230 364 791 945 723 790 680 695 66 75 70 1 423 794 606 86 591 69 985 398 174 78 707 288 591 439 70 920 1 481 923 12 735 869 929 715 404 327 342 672 948 169 704 867 158 182 80 476 228 999 406 891 898 79 800 5 295 366 436 832 784 19 45 174 809 781 71 320 983 608 263 142 267 869 595 602 728 458 721 954 639 85 170 5 733 374 487 619 99 522 462 389 301 987 171 82 481 620 433 769 724 553 918 167 196 90 259 477 270 615 148 478 520 924 600 286 761 581 120 768 321 311 468 436 143 236 848 599 560 947 376 55 600 661 464 796 663…
Output: 489501

Example 2:

Input: 208 520 178 447 350 414 848 471 587 675 351 151 597 348 86 323 912 528 183 41 331 66 501 918 238 816 751 670 725 653 803 607 105 85 283 614 252 120 940 900 484 829 37 473 208 80 4 97 9 615 685 608 572 345 473 524 507 358 160 915 413 333 355 125 523 478 170 433 9 56 863 195 490 417 191 505 759 429 233 536 87 762 826 29 53 466 86 983 793 557 824 113 660 847 166 787 346 951 195 514 437 971 981 676 637 704 674 30 204 432 219 498 581 929 114 298 627 659 696 411 625 461 893 725 24 414 779 537 963 865 607 348 41 173 623 119 294 595 589 835 787 2 395 839 268 885 258 19 401 498 684 927 41 499 101 930 380 113 870 934 603 555 435 623 73 876 714 219 111 92 262 418 222 495 631 476 225 638 540 417 901 345 142 460 475 701 17 125 520 254 848 85 955 857 955 756 881 387 162 951 365 633 647 351 180 919 582 6…
Output: 95920

Example 3:

Input: 649 738 441 896 128 669 217 879 33 873 608 580 788 159 939 527 359 159 469 305 209 872 846 418 947 988 923 230 609 611 889 368 495 985 586 515 16 451 872 338 857 994 450 606 354 752 215 870 941 375 474 243 898 924 960 590 913 294 928 440 61 537 640 384 877 133 69 53 911 798 323 362 904 202 812 721 167 985 614 403 939 376 976 84 794 387 276 903 120 219 647 436 873 499 978 300 208 184 794 900 808 634 790 380 318 263 843 78 12 371 259 124 690 377 941 514 576 76 690 323 392 249 841 818 497 315 112 358 360 412 351 693 124 171 602 727 907 862 815 661 27 204 955 215 271 630 897 227 895 247 38 179 638 214 969 897 589 130 539 989 358 126 13 826 89 419 102 177 788 290 298 431 699 354 499 851 428 625 26 572 844 490 628 265 764 924 154 369 274 306 727 723 892 445 769 939 913 543 66 263 56 692 712 758 …
Output: 300243

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
The Rain Ledgers at Thornveld - MEDIUM Coding Problem | CodeTikki