#P15120. [ICPC 2024 LAC] Fair Distribution
[ICPC 2024 LAC] Fair Distribution
题目描述
An entrepreneur has blueprints, each describing a type of building. Each blueprint specifies the building’s height through two integers and .
- : Height of the ground floor. It can be zero, indicating that the building has no ground floor.
- : Height of each residential floor. Each building has at least one residential floor.
The entrepreneur wants to distribute all of these blueprints among their two children Alice and Bob. Each child will build exactly one building from each blueprint allocated to them, choosing the number of residential floors for each building.
The entrepreneur wants to avoid showing favoritism towards either child, so they are looking for a fair distribution of the blueprints. They decided that a fair distribution is one in which it is possible to construct the buildings in such a way that the sum of the heights of the buildings constructed by each child is the same. Can you tell whether a fair distribution exists?
Consider the following example for blueprints:
- and (possible heights are );
- and (no ground floor, possible heights are );
- and (possible heights are ).
In this case a possible fair distribution is assigning the second blueprint to Alice and the rest to Bob. Even though Alice receives a single blueprint while Bob receives two, they may construct two residential floors on the first building type (height 3), two residential floors on the second (height 6), and one residential floor on the third (height 3). In this way, the sum of the heights of the buildings constructed by each child would be 6.
输入格式
The first line contains an integer () indicating the number of blueprints.
Each of the next lines contains two integers () and () denoting respectively the height of the ground floor and the height of each residential floor specified by the corresponding blueprint. The sum of the heights of the ground floors of all blueprints is at most .
输出格式
Output a single line with the uppercase letter "Y" if there exists a fair distribution of the blueprints, and the uppercase letter "N" otherwise.
3
1 1
0 3
2 1
Y
3
3 2
2 1
3 2
Y
3
1 10
2 20
4 30
N
1
1 1
N