CT40095

Ivory scrolls Rain Ledgers

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The council of the willow walks of Reedmarsh pays by the answer, and Quin intends to earn it. First: the full register of scrolls. 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 <= 2856; 0 <= a[i] <= 1000000.

Example 1:

Input: 568 30251 130182 576245 391319 226830 708907 582485 117525 892517 164987 147944 251014 780897 945881 888898 206832 272679 560264 449240 425739 582358 139758 155579 246809 677681 74013 123097 552172 478346 555683 140376 739940 576304 601624 96313 415681 952508 62907 370344 606002 972805 753695 747361 666820 878832 498083 777549 688619 667763 138400 718156 36416 368156 476582 803936 136479 496620 533538 446931 48161 801733 152821 168093 273360 203348 883292 168904 762511 861187 440442 296181 9096 144776 750262 336032 56194 313698 280161 747542 454714 244557 554231 49952 652585 945608 963748 392067 1919 52990 667096 752148 762281 240673 147028 234383 710565 299487 30915 350813 599068 711021 773078 174263 204332 158033 353105 608917 199508 977451 768756 739351 353740 67608 696024 22014 142953 …
Output: 282115903

Example 2:

Input: 2474 886881 779301 81801 522308 384045 117414 683798 698555 382440 197027 549159 923034 57610 374098 241017 309552 866253 184960 871122 903874 204205 761707 693977 887432 404314 472705 718908 173405 933033 486336 719327 152464 676587 641450 340077 116732 911536 513478 870597 614718 867882 776596 424687 923071 955869 41026 626439 160434 969310 660343 329920 602105 204986 298005 802649 693753 322649 871944 13471 884816 210459 937986 150762 820089 933929 564112 996104 168237 188241 608004 707800 265682 995686 403223 88430 912093 371144 696034 904689 900535 557779 765715 372522 785226 466224 726417 535310 76096 401958 110864 17315 88479 830451 769046 115607 646542 240391 409920 902676 549980 564140 84272 281291 950499 151768 45258 710229 489155 521219 710015 600586 80651 572294 930317 651865 5…
Output: 1220313595

Example 3:

Input: 2398 604181 253684 148871 376554 205917 185861 583706 378038 879728 165875 256702 403000 308565 438335 993362 80008 708703 576860 67720 63733 925876 630986 445780 184952 801792 420417 572379 126628 35246 934731 72782 919077 720574 424464 7455 722036 55092 737745 717480 551887 107068 326039 191808 978030 607785 99392 779809 15079 112872 79088 629550 938439 396316 78875 830651 891655 950329 396607 411266 980504 108488 173316 738245 197072 60299 636333 837556 752733 774691 758729 357040 383916 840344 329809 426521 290209 185983 81104 610437 239761 295598 637683 98978 103195 626256 580530 696275 795151 200214 249210 199449 583157 598708 680358 249675 467891 995470 534748 195800 323923 721027 192217 450672 999220 251203 229494 961854 813152 614583 859644 633471 110712 468574 383921 361739 15203…
Output: 1206698069

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.