CT58483

Lysander's Rain Ledgers Ledger

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

Morning light hits the island market of Coralcove as Lysander unrolls the day's manifest of stretches. 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 <= 2161; 0 <= a[i] <= 1000000.

Example 1:

Input: 378 253113 372234 143842 352403 433262 826573 799463 212561 891278 399487 247044 280783 683681 238770 333519 479433 869391 272321 533242 777433 612444 161261 138842 326833 771880 766426 60994 971156 525962 321550 699385 358733 812920 125034 917481 953044 142799 607532 621801 193768 876086 991573 182017 695199 740918 512526 927867 171686 470684 752661 662718 51698 144159 191728 736349 309511 287612 342387 651137 138570 383264 854406 529204 384186 79442 959604 542522 756097 409167 685079 466773 173100 492564 175212 472741 24426 105921 20822 514709 464790 49008 439268 613078 47482 769090 780546 556935 404388 156146 553431 296516 109424 287381 539849 440948 96676 232636 403730 54009 193326 194182 462987 596622 901184 679792 58654 312312 77743 757173 964061 670897 7224 507749 306713 48164 65629…
Output: 183510015

Example 2:

Input: 1407 477795 754075 193354 287585 563885 763627 104754 952642 636155 498984 84472 243975 771128 233368 996449 292455 562389 599175 226144 204999 328567 400065 543955 693637 28877 322042 545189 126116 231529 28213 798102 649256 422768 718249 978862 71453 424935 76937 169996 428886 181961 467166 542852 354176 655026 558389 368248 872992 24493 433771 976595 941173 513106 980576 79110 638740 266104 690606 292906 472513 985561 690472 985564 976460 354141 363273 518853 32627 549960 281061 759821 322859 665008 733508 320022 155104 359123 104896 202175 396193 671648 551651 447603 365098 68385 123681 610493 773886 157430 684043 829315 301199 358663 906901 96343 255586 699546 224712 960687 37069 521454 636758 853644 730591 542285 4130 437111 468933 173016 609025 168734 969590 207035 484363 965375 677…
Output: 691515255

Example 3:

Input: 598 685890 200423 393260 695465 525973 125099 512763 360532 775813 871686 90864 551070 328990 347777 444466 144903 567383 971956 303882 321140 915008 992509 251524 866407 707719 941223 484829 811920 288406 392271 898351 642624 295871 91346 234763 362001 287282 572524 652865 680048 954511 715213 71896 998618 715695 787772 564445 555348 14353 593365 214695 638425 845065 405663 596358 359145 928238 200818 941511 275098 391672 652671 684154 437865 119920 780541 768960 561201 318170 537367 376482 234073 320754 229286 69835 55219 925343 668722 175695 778602 908802 830669 943295 748158 564245 443357 303937 952703 591228 474405 522219 201314 880669 806814 869395 804968 285096 218015 979934 595668 4676 399910 639086 547628 111623 982543 768858 613008 919152 671746 741810 655105 203061 787612 698525…
Output: 274093987

Constraints:

1 <= n <= 2161; 0 <= a[i] <= 1000000.

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