#BS0000350. Chìa khóa văn phòng (Office Keys)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Chìa khóa văn phòng (Office Keys)
Office Keys
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
There are people and keys along a straight line. The office is at coordinate , person starts at , and key is at .
Each person must travel to a key, collect it, and then reach the office. A key can be collected by only one person, even if several people arrive at it simultaneously. Passing a key without collecting it is allowed. People may move simultaneously at a speed of one distance unit per second.
Find the earliest time when all people have arrived at the office, each with a key.
Input
- The first line gives integers : the numbers of people and keys and the office coordinate.
- The second line gives the initial positions in arbitrary order.
- The third line gives the key positions in arbitrary order.
Output
Print the minimum time in seconds as an integer.
Subtasks
- Subtask 1 (20 points): ; ; ; for all ; for all ; the are pairwise distinct and the are pairwise distinct; a person and a key may share a position.
- Subtask 2 (30 points): ; ; ; for all ; for all ; the are pairwise distinct and the are pairwise distinct; a person and a key may share a position.
- Subtask 3 (50 points): ; ; ; for all ; for all ; the are pairwise distinct and the are pairwise distinct; a person and a key may share a position.
Examples
Input 1
2 4 50
20 100
60 10 40 80
Output 1
50
Explanation
The person at collects the key at and reaches in seconds. The person at uses the key at and takes seconds. The second person must travel at least units to the office, so no earlier finish is possible.
Input 2
1 2 10
11
15 7
Output 2
7
Explanation
Using the key at takes seconds; using the key at takes seconds. The latter is faster.