Logo
(追記) (追記ここまで)

33762번 - Package Pickup 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
4 초 2048 MB1322100.000%

문제

Farmer John has distributed cows and packages in a weird pattern across the number line using the following process:

  • Farmer John chooses a number $M$ (1ドル \le M \le 10^{18}$).
  • Farmer John chooses $N$ (1ドル \le N \le 2 \cdot 10^4)$ intervals $[L_i, R_i]$ to distribute cows in (1ドル \le L_i \le R_i \le 10^{18}$). He then places cows at locations $L_i, L_i + M, L_i + 2M, \ldots, R_i$. It is guaranteed that $R_i - L_i$ is a multiple of $M$.
  • Farmer John chooses $P$ (1ドル \le P \le 2 \cdot 10^4)$ intervals $[A_i, B_i]$ to distribute packages in (1ドル \le A_i \le B_i \le 10^{18}$). He then places packages at locations $A_i, A_i + M, A_i + 2M, \ldots, B_i$. It is guaranteed that $B_i - A_i$ is a multiple of $M$.

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.

제한

예제 입력 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

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:

  • Issue 3ドル$ lefts to cow 1ドル$ so that it picks up package 1ドル$
  • Issue 3ドル$ rights to cow 3ドル$ so that it picks up package 7ドル$
  • Issue 4ドル$ rights to cow 2ドル$ so that it picks up package 5ドル$
  • Issue 10ドル$ rights to cow 1ドル$ so that it picks up packages 2ドル,ドル 3ドル,ドル and 4ドル$
  • Issue 2ドル$ rights to cow 2ドル$ so that it picks up package 6ドル$

예제 입력 2

2 1 1
1 5
2 6

예제 출력 2

3

There are three cows and three packages. Farmer John can issue one right to each cow.

힌트

출처

Olympiad > USA Computing Olympiad > 2024-2025 Season > USACO 2025 US Open Contest > Platinum 3번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /