RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
USACO0667

Compatible Pairs

Silver II 실버 II
난이도
2s
시간 제한
256MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

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?

Problem credits: Benjamin Qi

제약

SCORING

  • Inputs 3-4: \(A=B\)
  • Inputs 5-7: \(N\le 1000\)
  • Inputs 8-12: No additional constraints

Problem credits: Benjamin Qi

입력 형식

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
출력
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
출력
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.

문제 정보

riseoj 작성

출처 올림피아드 > USACO > 2024-2025 > US Open > Silver

태그

평가 및 의견

Compatible Pairs

개요
출제자 난이도 Silver II 실버 II 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Compatible Pairs

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8