Reza has established a restaurant which is located on the top floor of an…
- User
Reza has established a restaurant which is located on the top floor of an earthquake-proof building. In case of an earthquake, the building leans to the left, Reza n There is a table in the restaurant i i th in distance d i d i There is a meter from the entrance door (note d i d i It can be negative or positive; Negative means the table is on the left and positive means the table is on the right of the door).
The building manager warned Reza that if the building tilts to the left, the tables will slide to the left unless he sticks them to the floor. In fact, any table attached to the floor will not move, otherwise it will slide far enough to the left to reach the table to its left (assuming the width of the tables is small enough that several tables can fit within the same distance from the door). Also, if there is no table on the left side of the table that is not attached to the ground, it will be thrown out of the window and the restaurant will be closed. Reza has decided to stick some tables to the ground and push the rest after the end of the earthquake and return them to their original place.
Reza pays his student to do the work. The student gets a thousand tomans for every one meter he pushes a table. Money sticking to the table i i to the ground, t i t i It is a thousand tomans. (which can be positive or negative, if t i t i If it is negative, Reza takes money from his student for gluing the table!)
You have to write a program that calculates the lowest possible cost of gluing and pushing the tables in case of an earthquake.
Note that a table should not fall out of the window, otherwise the restaurant will be closed and Reza will go bankrupt.
input In the first line of the number n n means the number of tables. 1 ≤ n ≤ 2
800 1≤n≤2 800 In the second line, n n number comes that d i d i are It is guaranteed that no two tables are initially at the same point. ( d i ≠ d J ) (d i
= d J )
Finally, in the third line, n n number comes that t i t i are
2 30 ≤ d i , t i ≤ 2 30 -2 30 ≤d i ,t i ≤2 30
output On the only output line, print the lowest possible cost of sticking and pushing the tables.
Example Sample entry 1 3 0 2 10 5 6 13 Plain text Sample output 1 17 Plain text Only the leftmost table needs to be pasted. In this case, 5 thousand tomans is the cost of gluing it, and the other two tables slide towards it, and the cost of pushing them to their first place is 10 + 2 = 12 thousand tomans, and we spend a total of 17 thousand tomans.
Sample input 2 4 -4 -3 14 -1 100-410 Plain text Sample output 2 97 Plain text In this example, it is better to stick all the tables to the ground and we spend a total of 97 thousand tomans.
Sample entry 3 4 6 2 5 3 1 7 100 2 Plain text Sample output 3 12 Plain text The second table must be glued so that it does not fall out of the window. If we attach the first, second and fourth table, we will pay 10 thousand tomans. 2 thousand tomans is the cost of pushing the third table and we spend 12 thousand tomans in total.
- Assistant