CT65213

Kabir and the Bronze ribbons

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

At the snowberry thicket of Winterholt, Kabir 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 <= 2929; 0 <= a[i] <= 1000000000.

Example 1:

Input: 2479 251465632 591033426 631021863 397642297 11950843 889936116 682476845 419167675 211228264 447245185 10564007 593086945 23597601 85109519 932082535 627366628 255924765 321151935 319578281 296704283 330967080 585241131 828416991 425814080 876294000 256981506 600350162 894384346 970145635 979845522 431214614 575069404 683044724 198360151 504957934 767114027 973056507 714796211 694583811 971351018 296096302 79578183 182997023 202933300 114279522 513640410 725740065 188950100 17565360 63635463 387125485 749351987 562747143 240883196 118024803 748359535 500568494 100518857 14298141 489493900 635852777 704241649 445146900 209711431 675206890 713541417 954781648 740444849 510845514 322375653 415966287 621883357 91979640 404406591 872547449 229152604 399775747 864535806 778183150 123144658 3135…
Output: 1199842128456

Example 2:

Input: 450 926532109 304349415 940361691 576132408 485318798 388825486 813413641 133510847 836261827 818195798 593669617 79259138 166637414 600715977 355268912 571586618 194929048 594503069 319113956 584569520 607474575 389023305 559008808 736790218 359203027 976152744 491763632 138522286 105245496 4626806 235211755 73671165 29643151 859389970 261097311 588441354 702338993 840924632 513738278 917532919 343034444 282921659 357320946 834319004 37177963 410309192 98788308 395715038 370888920 482118038 963194002 806994274 224650398 603381191 135842685 369293520 335187184 414731469 720674623 8142578 738481848 735952053 652078256 454282187 267354898 425562258 961478271 798421330 600544171 463678851 326708899 500953248 95433726 462504861 350104582 23450547 45146501 166562343 238959954 306813906 59575695…
Output: 220176170509

Example 3:

Input: 651 953572940 379157521 655173002 51518586 85693518 924168699 500619037 528510627 2768561 705101621 753691704 423865767 588382435 31320177 583420687 359703208 296960765 436660545 524183261 228942039 507296036 160571500 966131263 711190015 647044773 139974714 815893560 776048498 455092034 136805953 45562681 942129964 276850677 679039063 254085965 42774164 396625386 932750452 287630622 952796530 858535212 587220173 759483002 280122830 132205330 302835288 358206361 221064564 107051751 939346798 804949016 282907075 717557453 584192631 759017499 92897042 476216887 847395074 971632429 298550967 522233509 795130200 582910814 901386892 92422418 21392530 113309366 759504212 79469199 516424391 479556697 929683675 349830659 741079366 430573655 652316779 788404619 793630785 559419986 315286495 7199168…
Output: 318267799469

Constraints:

1 <= n <= 2929; 0 <= a[i] <= 1000000000.

Loading...
Test Cases:No test cases
No test cases available.
Kabir and the Bronze ribbons - MEDIUM Coding Problem | CodeTikki