#725
Unrated
Package Pickup
시간 제한
2s
메모리 제한
1024MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

Note: The time limit for this problem is 4s, 2x the default.

Farmer John has distributed cows and packages in a weird pattern across the number line using the following process: Farmer John chooses a number MM (1M10181 \le M \le 10^{18}). Farmer John chooses NN (1N2104)1 \le N \le 2 \cdot 10^4) intervals [Li,Ri][L_i, R_i] to distribute cows in (1LiRi10181 \le L_i \le R_i \le 10^{18}). He then places cows at locations Li,Li+M,Li+2M,,RiL_i, L_i + M, L_i + 2M, \ldots, R_i. It is guaranteed that RiLiR_i - L_i is a multiple of MM. Farmer John chooses PP (1P2104)1 \le P \le 2 \cdot 10^4) intervals [Ai,Bi][A_i, B_i] to distribute packages in (1AiBi10181 \le A_i \le B_i \le 10^{18}). He then places packages at locations Ai,Ai+M,Ai+2M,,BiA_i, A_i + M, A_i + 2M, \ldots, B_i. It is guaranteed that BiAiB_i - A_i is a multiple of MM. Once the cows and packages are distributed, Farmer John wants to see how long it takes the cows to pick up the packages. Every second, Farmer John can issue a command to a single cow to move one unit left or right of their current position with his handy walkie talkie. If a cow travels to the position where a package is located, they are able to pick it up. Farmer John wants to know the minimum time in seconds that it would take the cows to pick up every package.

입력

The first line contains MM, NN, and PP.

The next NN lines each contain two integers LiL_i and RiR_i.

The next PP lines each contain two integers AiA_i and BiB_i.

출력

Output a single integer, representing the minimum amount of time it can take the cows to pick up all the packages, given that every second, he can issue a single left/right command to a single cow.

예제 입력 1

100 3 7
10 10
20 20
30 30
7 7
11 11
13 13
17 17
24 24
26 26
33 33

예제 출력 1

22

예제 입력 2

2 1 1
1 5
2 6

예제 출력 2

3

점수

Input 3-4: It is guaranteed that the total number of cows and packages does not exceed 21052 \cdot 10^5 Inputs 5-10: It is guaranteed that N,P500N, P \le 500. Inputs 11-13: It is guaranteed that no intervals of packages or cows intersect. Inputs 14-20: No additional constraints.

코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Unrated0명 투표
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.