题面
Alice and Bob are playing a card game. The game consists of rounds, in each round both players score some points (from to ), and for each round, Alice’s score differs from Bob’s score. The player who scores more points in a round is considered the winner of that round.
In the first round, Alice scored points, and Bob scored . In the second round, Alice scored points, and Bob scored .
The winner of the game is the one who has the higher total score. If Alice’s total score equals Bob’s total score, the player who won more rounds is declared the winner. Alice wants to understand if Bob has a chance to win, or if she will definitely win regardless of the results of the -rd round. Help her determine this!
Please note that in each round, a player can score at least and at most points. Additionally, for each round, Alice’s score differs from Bob’s score.
Input
The first line contains a single integer () — the number of test cases.
Each test case consists of three lines:
- the first line contains a single integer () — the maximum number of points that can be scored in a round;
- the second line contains two integers and (; ) — the points scored by Alice and Bob respectively in the first round;
- the third line contains two integers and (; ) — the points scored by Alice and Bob respectively in the second round.
Output
For each test case, output NO if Alice will win regardless of the results of the third round, or YES if Bob has a chance to win.
思路
因为题目说 “获胜者为总分较高的一方”,所以我们比较第三轮的极端情况:“爱丽丝不得分而鲍勃得到最大分”,在这个情况下,如果鲍勃的总分都没有爱丽丝的总分高,那么鲍勃就不可能赢,反之,鲍勃有机会赢得比赛
代码
#include <bits/stdc++.h>using namespace std;
int main() { ios::sync_with_stdio(false); cin.tie(nullptr);
int T; cin >> T; while (T --) { int k; cin >> k; int a1, b1, a2, b2; cin >> a1 >> b1 >> a2 >> b2; if (a1 + a2 < b1 + b2 + k) { cout << "YES" << endl; } else { cout << "NO" << endl; } }}