Homework
题号:NC253174
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

Colin has n optional courses numbered from 1 to n, so he has to do a lot of homework.

For the i-th course, Colin must write an essay with no less than a_i words. And Colin can write one word per second.

However, Colin wants to finish homework as fast as possible, so he decides to reuse his homework. For the i-th course homework, he can write a_i words directly, or spend c_i(c_i< a_i) seconds to copy and modify previous finished homework j(j\not=i). If a_j\ge a_i, he will just keep a_i words. But if a_j< a_i, he has to write another a_i-a_j words. Notice that Colin can finish his homework in any order.

Colin doesn't have enough time to make his homework plan because of the deadline, so he wants you to write a program to determine the order of doing homework so that he can finish homework as fast as possible(no matter write or copy).

输入描述:

The first line contains one integer n \text{ } ( 1 \le n \le 10^5 ).

The second line contains n integers a_1,a_2, \cdots ,a_n \text{ } ( 2 \le a_i \le 10^5 ).

The third line contains n integers c_1,c_2,\cdots,c_n\text{ } (1 \le c_i< a_i).

输出描述:

Print one integer representing the minimum number of seconds required to finish all homework.
示例1

输入

复制
5
800 1500 1000 2000 3000
50 40 60 80 100

输出

复制
3230

说明

Finish the fifth homework first, and copy the fifth homework to others.
The number of seconds is 3000+50+40+60+80=3230.