atcoder#AGC053D. [AGC053D] Everyone is a winner
[AGC053D] Everyone is a winner
Score : points
Problem Statement
We have a contest with participants and problems. The participants are numbered through . For each pair of a participant and a problem, we know the time it takes for the participant to solve the problem, and it is , , or minutes. Among the problems, there are problems that Participant takes minute to solve, problems that s/he takes minutes to solve, and problems that s/he takes minutes to solve.
Determine whether it is possible for the following to hold for every when the participants can freely decide the order they solve the problems.
- Let be the total time Participant takes to solve the first problems, and be the total time Participant takes to solve the first problems. Then, we have .
In other words, determine whether it is possible that Participant places first (possibly with ties) when they have solved the first problems, ignoring the time it takes for them to switch between problems.
Given test cases, solve each of them.
Constraints
- The sum of over all test cases is at most .
Input
Input is given from Standard Input in the following format. The first line is as follows:
Then, test cases follow, each in the format below:
Output
For each test case, print Yes
if the condition in Problem Statement can be satisfied, and print No
otherwise.
Use one line for each test case. (The checker is case-insensitive: we will accept both uppercase and lowercase letters.)
2
3
0 2 1
0 1 2
1 1 1
3
0 2 1
0 0 3
1 1 1
Yes
No
In the first test case, one scenario that satisfies the condition is as follows:
- Participant solves the first problem in minutes, the second in minutes, and the third in minutes;
- Participant solves the first problem in minutes, the second in minutes, and the third in minutes;
- Participant solves the first problem in minutes, the second in minutes, and the third in minutes.