CT63425

Cyrus and the Rain Ledgers

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

Caravans arrive at the otter slides of Sleekwater with crates of segments, and Cyrus the valuer must account for every last one. 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 <= 2513; 0 <= a[i] <= 1000.

Example 1:

Input: 2412 50 2 799 987 485 749 1000 777 753 622 40 289 495 850 748 355 290 461 779 812 230 819 407 303 748 793 822 991 844 991 924 939 169 56 890 322 796 197 18 303 601 424 147 77 790 402 527 346 498 789 881 131 461 686 126 321 871 559 144 395 450 619 382 416 951 442 767 384 530 822 150 449 979 732 310 769 560 298 378 789 849 778 414 636 688 59 609 991 747 277 974 797 988 738 400 757 341 718 0 260 331 573 604 706 226 730 478 742 752 85 18 672 699 827 776 4 525 305 185 904 567 484 659 546 510 708 223 241 660 865 592 757 430 233 549 689 728 643 595 997 253 531 730 380 563 438 565 371 581 160 537 515 449 716 781 617 597 333 532 549 144 550 37 708 315 427 358 532 363 139 492 1 948 25 673 862 632 410 565 729 250 723 487 107 628 64 618 832 10 637 167 767 78 978 105 401 586 374 650 534 265 432 229 435…
Output: 1204223

Example 2:

Input: 1764 513 747 291 935 696 217 72 203 973 138 332 381 68 991 837 613 683 898 762 585 78 757 320 262 504 4 865 503 504 314 432 144 456 342 301 100 747 621 285 823 361 361 813 2 142 298 962 779 634 838 319 236 772 609 453 373 816 829 210 495 865 629 403 27 325 794 601 555 344 311 396 563 391 175 196 112 748 217 751 96 129 324 777 890 460 63 446 149 286 308 47 75 824 244 492 542 444 674 568 491 819 17 613 782 20 691 601 891 375 917 154 105 93 997 146 138 511 8 292 59 867 481 321 887 505 744 93 217 562 407 543 697 274 322 782 269 564 916 262 973 4 46 223 395 885 0 571 904 843 31 259 347 835 623 136 343 712 284 624 693 945 701 971 257 113 923 401 733 912 448 38 550 885 168 849 290 713 968 221 336 478 51 223 879 456 724 410 641 666 463 964 490 84 815 587 977 683 294 786 938 156 96 540 31 300 717 4…
Output: 878550

Example 3:

Input: 2156 178 115 245 981 401 421 627 293 357 917 190 293 744 254 227 406 390 405 397 458 523 607 292 385 456 934 366 31 120 69 534 812 557 363 110 338 949 545 455 245 400 420 248 999 454 317 399 132 105 220 332 94 302 351 788 813 608 634 20 705 376 238 18 866 554 224 822 989 616 578 758 484 519 8 391 214 425 543 257 684 968 274 326 310 448 69 748 465 964 100 380 569 137 391 869 451 377 582 315 805 498 753 797 453 898 726 693 295 68 106 737 75 843 454 920 229 104 46 102 178 690 818 629 341 156 333 594 278 886 215 191 323 467 537 948 21 481 93 465 656 873 330 483 76 956 266 979 995 489 588 493 228 979 249 159 872 751 23 728 772 885 36 42 177 421 266 400 261 95 3 134 916 494 346 602 944 788 816 260 501 206 485 881 190 411 556 856 581 3 134 282 750 377 496 385 224 868 596 719 127 217 842 226 21 98…
Output: 1089843

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Cyrus and the Rain Ledgers - MEDIUM Coding Problem | CodeTikki