#P11769. 歌唱练习

    ID: 11183 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>贪心洛谷原创O2优化洛谷月赛

歌唱练习

Description

Tianyi has made a practice plan spanning nn days. She works extremely hard, and her daily practice duration must be monotonically non-decreasing. Meanwhile, to protect her voice, she can practice for a maximum of tit_i units of time on the ii-th day. The effectiveness of practice varies from day to day, influenced by factors such as weather, and we quantify the effectiveness of practice on the ii-th day as wiw_i, indicating that every unit of time she practices on that day will increase her familiarity by wiw_i. Note that it is possible for wiw_i to be less than 00, meaning that perhaps due to factors like excessive heat, her practice may have a negative impact.

Now, Tianyi has researched the weather forecast for the next nn days and estimated the values of tit_i and wiw_i for each day. Please determine the maximum amount her familiarity can be improved.

Input Format

The first line of input contains an integer nn — the number of days in Tianyi's practice plan.

The second line of input contains nn integers tit_i — the maximum units of time Tianyi can spend on practicing on each day.

The third line of input contains nn integers wiw_i — the effectiveness of practice on each day.

Output Format

The only line of output contains an integer — the maximum amount her familiarity can be improved.

3
3 2 3
2 -1 1
5

Hint

Sample Explanation

She practices for 22 units of time on the first day,increasing her familarity by 44;
She practices for 22 units of time on the second day,increasing her familarity by 2-2 (decreasing by 22);
She practices for 33 units of time on the third day,increasing her familarity by 33.
Tianyi's familiarity has increased by a total of 5.

It can be proved that there is no way to increase her familiarity higher than 55.

Constraints

Subtasks Applied. You can only gain the score of the subtask if you accepted all the tests in the subtask.

Subtask ID nn\le tit_i\le Special Property Score
11 1010 1010 No 1010
22 10910^9
33 100100
44 50005000 50005000
55 10910^9
66 10510^5
77 10610^6 11 55
88 10910^9 Yes 1515
99 No 2020

Special Property: tit_i is uniformly randomly generated in [0,109][0,10^9]

For all tests, it is guaranteed that 1n1061\le n\le10^60ti1090\le t_i\le10^91000wi1000-1000\le w_i\le1000.