Compatible Pairs

시간 제한2초메모리 제한2048 MB

요약
서로 다른 ID를 가진 소들이 그룹별로 존재하며, ID 합이 A 또는 B인 두 소를 짝지어 최대한 많은 짝을 만든다.
난이도

어려움10점 중 8점

유형
그래프, 그리디, 해시맵
정답자
아직 제출이 없습니다

문제

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 NN (1≤N≤2⋅1051\le N\le 2\cdot 10^5) unique ID numbers, and for each unique ID d_id\_i (0≤d_i≤1090\le d\_i\le 10^9), there are n_in\_i (1≤n_i≤1091\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 AA or BB (0≤A≤B≤2⋅1090\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 NN, AA, BB.

The next NN lines each contain n_in\_i and d_id\_i. No two d_id\_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++).

예제2

  1. 예제 1

    입력
    4 4 5
    17 2
    100 0
    10 1
    200 4
    
    예상 출력
    118
    
  2. 예제 2

    입력
    4 4 5
    100 0
    10 1
    100 3
    20 4
    
    예상 출력
    30