cswork / OAOpen practice workspace

SalesforceOA #23

Least Hours to Implement Features

Estimated MediumJudge-ready

Topics (AI-labelled)GreedyPrefix & Ranges

Each feature must be either developed or integrated. There are enough developers, and all development starts at the same time; integration is done one feature at a time by the team lead alone, in parallel with development. Find the shortest time to complete all features.

Input

The input gives n, followed by n developmentTime values and n integrationTime values. There are no original numeric bounds; this site adds 1≤n≤200000, and all times are integers in 0..10^9.

Output

Output one integer answer.

Example 1

Input:

4
3 4 5 9
3 2 5 5

Output:

5

Example 2

Input:

4
8 10 6 7
1 2 2 1

Output:

6

Example 3

Input:

2
0 5
9 0

Output:

0

Example notes

The outputs of the three public examples are, in order: 5; 6; 0. They have been checked by independent enumeration or direct simulation.

Editorial

Loading solution…