【编程题解】One piece

Description

Luffy wants to find one piece through the great route, and there are many other pirates on the road to stop him.

He knew that as long as he defeated the pirate with some physical strength, the pirate would always escort him.

On the way, he will meet N pirates in turn, each pirate has its own force value and the physical value required to defeat him.

If Luffy did not defeat a certain pirate, and this pirate's force value was greater than the sum of the pirate's force value escorting him, the pirate would defeat him.

Luffy wants to know that if he wants to successfully cross a great route without being defeated, he needs at least as much physical strength

Input

The first line contains the integer N, indicating the number of pirates.

The second line contains N integers d1, d2, ..., dn, which represent the force value of each pirate.

The third line contains N integers p1, p2, ..., pn, which represent the physical value required to defeat N pirates.

Data range:1≤N≤50,1≤di≤10^12,1≤pi≤2

Output

An integer is output, indicating the minimum physical strength required.

Sample Input 1 

3
8 5 10
1 1 2

Sample Output 1

2

Personal Answer  (using language:JAVA)  Not necessarily right

public class Main {
    public static void main(String[] args) {
        System.out.println("Unsolved");
    }
}

Welcome to communicate!

猜你喜欢

转载自blog.csdn.net/Ximerr/article/details/106751558