CT57676

Jaya's ribbons Reckoning

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

At the mountain city of Highreach, Jaya records each ribbons in a worn leather ledger. The guild wants answers, not guesses. 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 <= 1078; 0 <= a[i] <= 1000.

Example 1:

Input: 1063 897 71 514 706 103 618 452 253 994 98 579 740 644 504 934 606 487 495 371 25 587 43 701 980 268 265 654 245 46 794 210 576 311 73 279 673 683 628 296 393 594 18 74 388 849 228 458 579 348 14 609 687 204 624 323 402 438 606 631 398 350 874 463 634 785 479 114 610 45 180 648 691 739 596 344 714 64 485 798 568 618 774 864 427 429 132 74 902 23 67 24 437 227 501 215 825 342 799 736 59 523 816 477 473 156 325 668 49 1 130 880 651 96 604 131 851 356 267 490 726 291 258 66 324 552 363 800 919 14 761 848 374 876 518 258 762 446 987 709 305 600 765 889 719 755 967 361 418 904 71 679 420 415 837 847 512 7 353 289 438 916 393 223 321 19 121 142 840 942 63 755 254 920 591 101 87 466 859 132 240 435 465 105 155 83 522 131 858 784 548 803 820 177 622 929 189 554 937 401 92 367 543 5 171 527 157 600…
Output: 534716

Example 2:

Input: 42 734 85 662 280 58 326 162 825 634 923 396 832 855 553 399 150 59 739 795 857 409 624 349 586 642 419 820 23 30 156 511 965 759 286 771 929 929 509 348 612 310 601
Output: 13830

Example 3:

Input: 997 806 524 434 949 824 690 90 168 537 981 538 194 677 948 517 502 647 386 592 768 99 23 762 963 732 686 250 790 78 954 567 333 32 311 447 147 4 444 572 24 805 845 581 920 998 179 738 357 246 651 356 173 214 223 259 390 228 68 649 239 416 800 469 415 126 102 526 353 101 24 538 789 647 68 318 258 441 977 92 745 406 924 171 753 405 551 89 517 887 489 605 143 440 711 121 296 744 272 937 201 817 184 477 170 501 599 791 896 341 224 530 322 453 301 846 384 426 810 679 273 386 945 131 51 874 43 805 990 878 195 775 878 323 58 319 515 601 323 733 584 354 809 577 269 994 548 130 849 105 609 116 959 930 369 551 990 455 154 26 910 665 240 633 534 267 796 652 728 825 266 282 865 802 569 769 679 972 499 573 266 690 799 435 440 355 585 194 979 408 753 690 900 585 734 196 218 607 961 768 25 859 574 239 77…
Output: 480101

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Jaya's ribbons Reckoning - MEDIUM Coding Problem | CodeTikki