Pavel has a toy railway. It is very simple. There is a single main line consisting of stations. These stations are numbered from to in order along the line. The distance between the stations and is centimeters ().
Apart from the main line there may be some secondary lines. Each secondary line is a railway line between a station on the main line and a new station that does not lie on the main line. (These new stations are not numbered.) At most one secondary line can start in each station of the main line. The length of the secondary line starting at station is centimeters. We use to denote that there is no secondary line starting at station .
Pavel is now planning to build one shortcut: an express line between two different (possibly neighbouring) stations of the main line. Express line will have length of exactly centimeters, regardless of what two stations it will connect.
Each segment of the railway, including the new express line, can be used in both directions. The distance between two stations is the smallest length of a route that goes from one station to the other along the railways. The diameter of the whole railway network is the maximum distance among all pairs of stations. In other words, this is the smallest number , such that the distance between every pair of stations is at most .
Pavel wants to build the express line in such a way that the diameter of the resulting network is minimized.
Input Specification
Line of input will contain two space separated integers and , the number of stations on the main line and the length of the new express line, respectively.
Line of the input will contain , an array of length . The space separated integers give the distances between stations on the main line.
Line of the input will contain , an array of length . The space separated integers give the lengths of secondary lines.
Sample Input 1
4 10
10 20 20
0 40 0 30
Sample Output 1
80
Explanation for Sample Output 1
The optimal solution is the build the express line between stations and , as shown below.
The diameter of the new railway network is centimeters, so your program should output .
Sample Input 2
9 30
10 10 10 10 10 10 10 10
20 0 30 0 0 40 0 40 0
Sample Output 2
110
Explanation for Sample Output 2
The optimal solution is to connect stations and , in which case the diameter is .
Sample Input 3
4 1
2 2 2
1 10 10 1
Sample Output 3
21
Explanation for Sample Output 3
The optimal solution is to connect stations and , reducing the diameter to .
Sample Input 4
3 3
1 1
1 1 1
Sample Output 4
4
Explanation for Sample Output 4
Connection any two stations with the express line of length does not improve the initial diameter of the railway network which is .
Subtasks
In all subtasks, , , , .
- (9 points)
- (14 points)
- (8 points)
- (7 points)
- (33 points)
- (22 points)
- (4 points)
- (3 points)
Comments