#BS0000414. Điểm hẹn trên đường thẳng (Meeting on the Line)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Điểm hẹn trên đường thẳng (Meeting on the Line)
Meeting on the Line
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
There are people on a coordinate line, person living at . They choose a meeting point . Person first spends minutes dressing, then travels for minutes. Their total arrival time is . Everyone begins preparing simultaneously. Find the meeting coordinate that minimizes the time when everyone has arrived.
Input
The first line contains integer . The second line contains the integers in order from 1 to . The third line contains the integers in the same order.
Output
Print the unique optimal coordinate , not the time. The absolute or relative error must not exceed .
Subtasks
- Subtask 1 (20 points): ; for every . for every .
- Subtask 2 (30 points): ; for every . for every .
- Subtask 3 (50 points): ; for every .
Examples
Input
1
0
3
Output
0
Explanation
The only person is at 0 and needs 3 minutes to prepare. Meeting at 0 requires no travel and attains the lower bound of 3 minutes.
Input
2
3 1
0 0
Output
2
Explanation
The positions are 3 and 1, with no preparation time. Their distance is 2, so at least one must travel at least 1 unit. At point 2 both travel exactly 1 unit.
Input
2
1 4
0 0
Output
2.5
Explanation
The people need no preparation and are 3 units apart. At 2.5 both travel for 1.5 minutes; the sum of their travel distances is at least 3, so their maximum time cannot be below 1.5.
Input
3
1 2 3
0 0 0
Output
2
Explanation
At point 2 the arrival times are 1, 0 and 1 minutes. The outermost people are 2 units apart, so they cannot both arrive in less than 1 minute.
Input
3
1 2 3
4 1 2
Output
1
Explanation
At 1, arrival times are , , and minutes. Meeting before 4 is impossible because the first person needs 4 minutes to dress. To arrive by 4 that person cannot travel, so the meeting point is 1.
Input
3
3 3 3
5 3 3
Output
3
Explanation
All three people are at position 3, with preparation times 5, 3 and 3 minutes. At point 3 the maximum arrival time is 5 minutes. Any other point adds travel time for the first person.
Input
6
5 4 7 2 10 4
3 2 5 1 4 6
Output
6
Explanation
At point 6, the six arrival times are minutes. Person 5 starts at 10 with preparation time 4, and person 6 starts at 4 with preparation time 6. Their combined arrival times are at least minutes, so their maximum is at least 8 minutes. Point 6 attains this bound.