#P8726. [蓝桥杯 2020 省 AB3] 旅行家

    ID: 9830 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划 DP2020斜率优化蓝桥杯省赛李超线段树

[蓝桥杯 2020 省 AB3] 旅行家

Problem Description

Long ago, there were nn islands on the sea, numbered from 11 to nn. 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 RP\mathrm{RP} scholar), you want to start a trip from island 11 to gain more RP\mathrm{RP}. 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 RP\mathrm{RP} to the residents. Specifically, your RP\mathrm{RP} will be divided by 22 and rounded down (i.e., truncated toward zero). (When your RP\mathrm{RP} is negative, the residents still have to share the burden, because you have built a deep friendship.)

Island ii has TiT_i people. However, you are picky: each time you travel from island jj to island ii, you will only do Ti×TjT_i \times T_j good deeds on the island you arrive at. (Each good deed gives 11 point of RP\mathrm{RP}.)

The only downside is that staying on an island costs a lot. Staying on island ii deducts FiF_i points of RP\mathrm{RP}.

Note: When leaving an island, first halve your RP\mathrm{RP}, then deduct the lodging RP\mathrm{RP} cost, and finally do good deeds on the newly arrived island to increase RP\mathrm{RP}. When leaving island 11, you must deduct the lodging cost on island 11. 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 (RP\mathrm{RP}), so you start from island 11. Initially you have 00 points of RP\mathrm{RP}. You want to choose some islands to visit and finally stop at one island. Find the maximum possible RP\mathrm{RP} value.

Input Format

The first line contains an integer nn, the total number of islands.

The second line contains nn integers T1,T2,,TnT_1, T_2, \cdots, T_n, the population of each island.

The third line contains nn integers F1,F2,,FnF_1, F_2, \cdots, F_n, the RP\mathrm{RP} loss for lodging on each island.

Output Format

Output one number, the maximum RP\mathrm{RP} 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 11 to island 33 is optimal. Starting with 00 points of RP\mathrm{RP}, halving and truncating still gives 00. Deduct 1RP1 \mathrm{RP} for lodging on island 11. On island 33, doing good deeds produces 4×5=204 \times 5 = 20 points of RP\mathrm{RP}. Finally you get 1919 points of RPR P.

Constraints and Notes

For 20%20\% of the testdata, 1n151 \leq n \leq 15.

For 70%70\% of the testdata, 1n50001 \leq n \leq 5000.

For all testdata, 1n5×1051 \leq n \leq 5 \times 10^5, 1Ti200001 \leq T_i \leq 20000, 1Fi2×1081 \leq F_i \leq 2 \times 10^8. The given TiT_i 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