CT62643

Jasper ribbons Rain Ledgers

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

Librarian found an old ledger of ribbons in the studio attic at the silver mines of Lodebarrow. The margin notes pose a precise question. 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 <= 1711; 0 <= a[i] <= 1000000000.

Example 1:

Input: 340 336687877 729106841 94885758 367212786 881282575 531793342 648315414 27602144 78909915 121551342 207650808 400002519 100027010 413583279 789690368 353143614 441508710 93921792 803804441 891205407 554492634 812422319 110609323 833803143 655639855 426112062 383352287 628240785 1132388 245197382 139557864 855393919 933516592 445172041 293115520 760145970 486571606 41964188 632605677 950677618 844790161 586777915 625295761 61035166 192493202 244779473 4777915 542960102 338711792 685565560 356519395 384049851 216199660 542068488 791187163 414592938 973113976 275616888 135524475 926380076 602360217 185848430 953935368 456934505 988823006 56058244 835774253 419547020 63406216 836366021 292475867 838163198 792018225 314391479 554108475 43304737 331910303 438909111 815870803 551694517 767982051…
Output: 148993862650

Example 2:

Input: 1004 299212907 68154309 496534145 418172970 266785739 474591936 180985660 864347003 171584059 206969430 75553528 104259370 165218143 500434877 638605580 657980084 706322132 83399879 373374329 878237227 306513456 191299744 781846484 330498224 926025111 203579413 872797611 557777635 764165360 786599711 497240402 452318665 134447615 151138575 295590159 557541007 624834123 847328277 34687971 473077050 708894392 332501678 385771986 757334304 284742633 203260050 380790348 500408795 831348000 74687494 424765777 99733352 145373402 109886581 462416989 833612123 762115949 394370776 730800236 909524333 517569314 939451306 642490441 658547643 61201673 37177214 87519888 140430504 566509106 938083231 972115308 160860381 405249630 67898843 305238873 595526941 788776840 389705776 227861124 889905862 41006…
Output: 488895379592

Example 3:

Input: 1427 77134267 970656876 732220116 790357604 905666435 98580136 68553797 642926390 28140338 503720005 931090703 842008029 529341000 628046153 757401644 695764650 945310911 387219433 847103825 481538487 251517073 827226904 864668871 803185882 259744301 473165856 515445123 358733349 714973418 654689474 923418151 847990950 486338022 514661645 341311625 950025664 766528700 156088702 73440894 164180815 12404861 189979356 852753853 826774909 700835352 317367390 207749656 230385183 204515259 706892774 696719831 538195792 444959211 117370845 675392465 403555941 250099055 321713596 80608379 164824685 170647909 303653545 466581135 868903912 521612695 483090407 487562927 924653970 402335830 727317937 279878515 429648802 146638642 847018830 326659284 928568597 3409223 449261432 332079975 625339650 7264…
Output: 696444913288

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Jasper ribbons Rain Ledgers - MEDIUM Coding Problem | CodeTikki