| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 4 초 | 2048 MB | 13 | 2 | 2 | 100.000% |
Farmer John has distributed cows and packages in a weird pattern across the number line using the following process:
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 $M,ドル $N,ドル and $P$.
The next $N$ lines each contain two integers $L_i$ and $R_i$.
The next $P$ lines each contain two integers $A_i$ and $B_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.
100 3 7 10 10 20 20 30 30 7 7 11 11 13 13 17 17 24 24 26 26 33 33
22
In the above test case, suppose the cows and packages are numbered from left to right. Farmer John can follow this procedure to pick up the packages in 22 seconds:
2 1 1 1 5 2 6
3
There are three cows and three packages. Farmer John can issue one right to each cow.