#P8726. [蓝桥杯 2020 省 AB3] 旅行家
[蓝桥杯 2020 省 AB3] 旅行家
Problem Description
Long ago, there were islands on the sea, numbered from to . The residents were troubled by ocean currents and could not reach any island with a smaller number than the island they were currently on. After several years, the population on the islands increased with the island number (ties are allowed). As an excellent traveler (an scholar), you want to start a trip from island to gain more . Due to the ocean currents, you can only travel to islands with a larger number than your current island.
Because you are kind, when you leave an island you will distribute your to the residents. Specifically, your will be divided by and rounded down (i.e., truncated toward zero). (When your is negative, the residents still have to share the burden, because you have built a deep friendship.)
Island has people. However, you are picky: each time you travel from island to island , you will only do good deeds on the island you arrive at. (Each good deed gives point of .)
The only downside is that staying on an island costs a lot. Staying on island deducts points of .
Note: When leaving an island, first halve your , then deduct the lodging cost, and finally do good deeds on the newly arrived island to increase . When leaving island , you must deduct the lodging cost on island . When you arrive at the last island of your trip, you must finish doing the good deeds before the trip ends; that is, you do not need to deduct the lodging cost on the final island you arrive at.
You love traveling (), so you start from island . Initially you have points of . You want to choose some islands to visit and finally stop at one island. Find the maximum possible value.
Input Format
The first line contains an integer , the total number of islands.
The second line contains integers , the population of each island.
The third line contains integers , the loss for lodging on each island.
Output Format
Output one number, the maximum value you can obtain.
3
4 4 5
1 10 3
19
5
969 980 1013 1016 1021
888423 945460 865822 896150 946615
246172
Hint
Sample Explanation
Going directly from island to island is optimal. Starting with points of , halving and truncating still gives . Deduct for lodging on island . On island , doing good deeds produces points of . Finally you get points of .
Constraints and Notes
For of the testdata, .
For of the testdata, .
For all testdata, , , . The given are already sorted in nondecreasing order.
It is recommended to use 64-bit signed integers for calculations.
Lanqiao Cup 2020, Round 3 Provincial Contest, AB Group, Problem J.
Upd.2024.7.13 Hack data has been added.
Translated by ChatGPT 5