cswork / OAOpen practice workspace

Akuna CapitalOA #3

Update Release Scheduler

Estimated MediumJudge-ready

Topics (AI-labelled)Greedy

Release updates in non-decreasing order of plannedDate. Each update may use either alternateDate or plannedDate, and several updates may be released on the same day. Minimize the calendar day on which all updates are complete. Updates with equal plannedDate may be released in any order among themselves; the optimal choice is to process them in increasing alternateDate.

Input

The first line contains n; the second line contains n plannedDate values; the third line contains n alternateDate values. Original constraints: 1≤n≤200000, 1≤(elements of both arrays)≤10^9, alternateDate[i]≤plannedDate[i].

Output

Output the earliest completion day after all updates are released.

Example 1

Input:

4
3 7 4 9
1 5 2 3

Output:

9

Example 2

Input:

3
9 2 7
1 1 1

Output:

1

Example 3

Input:

4
3 2 7 8
1 1 5 6

Output:

6

Editorial

Loading solution…