AmazonOA #389
Minimum Time Spent
估计中等可在线判题
Each movie has a release time and a duration and can be started at any time after its release. Watch at least one movie of each of the two genres; you cannot watch two movies at once, but you may switch back to back with no gap. Find the earliest finish time; the two genres may be watched in either order.
输入格式
The first line contains n m; the next four lines are, in order, n comedy release times, n comedy durations, m drama release times, and m drama durations. Original bounds: 1≤n,m≤100000; all values in the four arrays are 1..10^6.
输出格式
Output a single integer answer.
样例 1
输入:
2 2
1 4
3 2
5 2
2 2
输出:
6
样例 2
输入:
1 1
10
1
1
2
输出:
11
样例 3
输入:
1 1
1
2
1
3
输出:
6
样例说明
The first example is 6: the comedy (release 1, duration 3) ends at 4, then watch the drama (release 2, duration 2). The original explanation described the movie released at 5 as starting at 4; this site corrects it. The second example is 11 and the third is 6.