#B4156. Interstellar Flight Scheduling
Interstellar Flight Scheduling
Interstellar Flight Scheduling
In the future, space travel has become commonplace. The Interstellar Department has announced a new route from Mars to Uranus. Every spaceship must first traverse Route (Earth (\to) Mars) and then Route (Mars (\to) Uranus) to successfully reach Uranus. To avoid collisions, each route can only have one spaceship in transit at any given moment. Spaceships may have to wait at Mars until the route is free, and the order in which they arrive at Mars can be different from the order in which they depart Mars.
Given (N) spaceships, where the (i)-th spaceship takes (U_i) time to travel from Earth to Mars and (V_i) time from Mars to Uranus, calculate the minimum total time required for all spaceships to reach Uranus.
inputFormat
The first line contains an integer (N) representing the number of spaceships. The second line contains (N) integers (U_1, U_2, \dots, U_N) where (U_i) is the time for the (i)-th spaceship to travel from Earth to Mars. The third line contains (N) integers (V_1, V_2, \dots, V_N) where (V_i) is the time for the (i)-th spaceship to travel from Mars to Uranus.
outputFormat
Output a single integer representing the minimum total time for all spaceships to reach Uranus.
sample
1
5
10
15