CT65098

Cressida's windows Reckoning

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

Deep in the old quarter of Brasshaven, Cressida studies rows of windows entries. One clean number will settle the guild's oldest argument. 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 <= 2207; 0 <= a[i] <= 1000000000.

Example 1:

Input: 1280 694279206 194384770 565960103 715373851 584910265 275500066 693969707 409780772 949172173 701955667 997849548 38302107 172541861 407167930 357835624 188271546 477459478 122240803 971671980 288123398 677372550 295732477 253325021 715847921 180929272 228881362 584086104 588203724 409054694 858131531 128639858 30415604 57989079 913732264 630016626 990985095 631944547 172682067 455354424 847701430 599308569 398689200 572855470 967517410 429031413 547561529 616117791 424204556 573224486 60283091 402448174 805650036 106971062 368734227 117335433 164729731 193784960 207191911 566792320 25496140 864082948 160141886 116754614 116917029 736200056 739065123 806969698 973355989 44580632 10882451 559973698 346891385 317461511 438048820 980832911 661652036 967799393 488562115 315365067 579267789 32…
Output: 635477655644

Example 2:

Input: 2180 883194626 5237230 98672957 857636452 254780000 669566180 34205165 51523199 121161919 383208840 84541120 970016908 466573347 244571322 524340464 83428049 75552838 466606104 873391033 724863157 198529358 578222246 604832745 148405908 974224085 924220199 482698818 296541614 709020151 939333070 864837538 868641811 175183605 21830423 447977283 42974718 180617248 904438523 926835995 652046654 816117472 42894082 748792841 702109128 533897161 869996563 92152216 477371092 384114103 917198896 170770874 912725567 771626480 765877245 814176517 688987595 854389569 127063343 110556488 915579994 626272076 564257719 410976650 856095440 564727552 845746826 15212114 836256045 603896412 391621350 928338679 624765016 148021437 346870199 106433234 54254040 924578739 410590832 375740680 769811355 345648152…
Output: 1055893555741

Example 3:

Input: 1350 48573270 602322735 899776505 90678195 115889797 991021721 817283361 167293268 736250238 996305027 905150884 507924526 697879575 291570277 460528191 424971926 804758018 248352178 763314461 668809067 278488799 432408654 292722679 845127840 362867972 676470146 57265170 152578315 529030222 11518118 657117560 950038616 940046024 393397829 224917807 30235006 106380278 476729960 309438698 681261691 280240028 312450418 750104006 935100920 744492059 280475585 449399687 822792769 532399528 89840169 954682684 721207789 343178545 222135813 214514632 391236455 317269245 420037203 313790884 342422465 673309421 803494131 533089942 758815969 330089113 507480308 870300346 983993915 288437562 76963304 18527739 97709376 141468606 544968877 423084905 506247953 71450813 84112219 598586965 714778202 944825…
Output: 669559133393

Constraints:

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

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