CT59096

Roving panels Rain Ledgers

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

Morning light hits the lily shoals of Padmore as Jaya unrolls the day's manifest of panels. The tally will decide the next shipment. 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 <= 2703; 0 <= a[i] <= 1000.

Example 1:

Input: 446 830 403 389 138 376 419 827 230 766 329 377 790 215 817 318 66 666 752 385 1 917 746 502 278 761 62 460 587 796 353 879 66 695 228 225 867 556 524 82 109 133 130 798 892 191 491 631 107 213 342 326 484 543 689 711 215 927 467 666 812 86 508 947 186 956 492 776 456 858 677 869 333 291 718 125 318 145 329 447 521 384 470 696 212 437 51 899 265 361 183 932 133 409 88 171 501 391 750 911 781 137 703 957 174 58 543 572 698 703 8 735 881 190 198 817 710 107 973 782 522 613 45 281 203 477 50 137 630 435 864 389 252 797 430 197 398 979 347 84 159 108 637 414 231 191 233 116 150 167 777 879 943 935 257 629 807 218 804 329 143 261 191 515 494 938 452 502 926 533 479 648 641 860 733 112 184 53 20 223 291 255 762 217 361 783 725 596 733 684 67 81 765 544 12 504 978 6 229 828 542 932 313 219 24 800…
Output: 211293

Example 2:

Input: 2360 656 716 845 653 439 477 650 82 235 694 691 777 1 61 393 796 326 429 117 361 254 368 303 175 298 479 525 699 517 279 375 630 805 516 880 673 611 811 70 661 250 205 373 549 189 915 782 17 110 147 793 592 324 153 869 909 43 582 238 916 795 339 772 370 176 750 318 541 176 237 321 219 882 270 362 917 873 746 237 857 744 98 298 104 8 72 567 210 990 971 299 894 618 992 576 239 32 410 38 703 264 695 89 118 748 358 845 236 314 815 849 648 720 673 819 804 524 603 291 364 408 688 885 700 685 594 109 387 973 323 357 430 787 381 321 553 391 127 485 499 151 226 563 229 462 177 777 742 306 582 985 658 579 375 560 415 910 149 507 429 320 776 904 928 44 183 988 538 38 872 93 90 388 90 437 99 355 576 210 47 41 736 562 108 110 958 622 819 611 57 266 746 468 753 890 620 945 959 887 83 633 674 329 129 616…
Output: 1176328

Example 3:

Input: 422 920 552 156 127 74 45 774 975 276 418 280 402 548 792 466 421 96 809 95 735 615 652 596 511 692 87 123 427 369 854 408 205 96 933 147 713 171 513 212 432 728 874 489 627 56 445 969 110 8 862 136 910 860 201 485 961 867 856 157 67 93 737 203 22 334 522 468 358 112 693 64 467 698 837 73 966 452 220 884 439 899 937 497 364 711 819 526 386 544 483 901 436 67 461 863 551 316 349 812 602 268 679 108 1000 597 782 663 256 30 877 310 956 322 636 947 799 534 261 317 780 206 483 138 374 240 203 751 602 434 506 11 553 300 109 0 652 495 535 328 203 151 175 794 112 321 421 172 682 739 18 190 929 549 427 8 697 910 386 603 166 44 106 454 436 108 794 8 341 869 697 277 316 202 731 497 87 503 610 158 999 497 956 482 859 268 747 507 184 818 597 172 958 245 93 133 925 908 453 378 309 343 110 534 302 908 26…
Output: 214406

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.