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

33767번 - Compatible Pairs 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 2048 MB120433634.615%

문제

Deep in the countryside, Farmer John’s cows aren’t just ordinary farm animals—they are part of a clandestine bovine intelligence network. Each cow carries an ID number, carefully assigned by the elite cow cryptographers. However, due to Farmer John's rather haphazard tagging system, some cows ended up with the same ID.

Farmer John noted that there are $N$ (1ドル\le N\le 2\cdot 10^5$) unique ID numbers, and for each unique ID $d_i$ (0ドル\le d_i\le 10^9$), there are $n_i$ (1ドル\le n_i\le 10^9$) cows who shared it.

The cows can only communicate in pairs, and their secret encryption method has one strict rule: two cows can only exchange information if they are not the same cow and the sum of their ID numbers equals either $A$ or $B$ (0ドル\le A\le B\le 2\cdot 10^9$). A cow can only engage in one conversation at a time (i.e., no cow can be part of more than one pair).

Farmer John would like to maximize the number of disjoint communication pairs to ensure the best information flow. Can you determine the largest number of conversations that can happen at once?

입력

The first line contains $N,ドル $A,ドル $B$.

The next $N$ lines each contain $n_i$ and $d_i$. No two $d_i$ are the same.

출력

The maximum number of disjoint communicating pairs that can be formed at the same time.

Note that the large size of integers involved in this problem may require the use of 64-bit integer data types (e.g., a "long long" in C/C++).

제한

예제 입력 1

4 4 5
17 2
100 0
10 1
200 4

예제 출력 1

118

A cow with an ID of 0ドル$ can communicate with another cow with an ID of 4ドル$ because the sum of their IDs is 4ドル$. Since there are a total of 100ドル$ cows of ID 0ドル$ and 200ドル$ cows of ID 4ドル,ドル there can be up to 100ドル$ communicating pairs with this combination of IDs.

A cow with an ID of 4ドル$ can also communicate with another cow with an ID of 1ドル$ (sum to 5ドル$). There are 10ドル$ cows of ID 1ドル$ and 100ドル$ remaining unpaired cows of ID 4ドル,ドル allowing for another 10ドル$ pairs.

Finally, a cow with an ID of 2ドル$ can communicate with another cow of the same ID. Since there are a total of 17ドル$ cows of ID 2ドル,ドル there can be up to 8ドル$ more pairs.

In total, there are 100ドル+10+8=118$ communicating pairs. It can be shown that this is the maximum possible number of pairs.

예제 입력 2

4 4 5
100 0
10 1
100 3
20 4

예제 출력 2

30

Pairing IDs 0ドル$ and 4ドル$ makes 20ドル$ pairs, while pairing IDs 1ドル$ and 3ドル$ makes 10ドル$ pairs. It can be shown that this is the optimal pairing, resulting in a total of 30ドル$ pairs.

힌트

출처

Olympiad > USA Computing Olympiad > 2024-2025 Season > USACO 2025 US Open Contest > Silver 2번

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

출처

대학교 대회

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

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