Search for a command to run...
Progressive hints first, then the full explanation and implementation when you're ready to cash out.
Review status
AI-generated and still unreviewed. Double-check the details before internalizing them.
Hints
Open only as much as you need to keep the solve alive.
Track the score difference after the first two rounds: . Positive means Alice is ahead, negative means Bob is ahead.
Bob only needs one possible third round. So give Bob the best possible third round: Alice scores as little as possible and Bob scores as much as possible.
The maximum amount Bob can reduce Alice's score lead by in round is , by choosing Alice's score and Bob's score . This is valid because and .
If , then after the best third round for Bob, the final total difference is , so Bob wins by total score. No tiebreaker drama, thank God.
If , even Bob's best possible third round cannot make his total score strictly larger. When , Alice must have won both first two rounds, so a tied total still goes to Alice by rounds. Therefore Bob has a chance iff .
Research check: the canonical statement is the Codeforces problem page for 2199A - Game, and the official Kotlin Heroes 14 tutorial page lists the reference solution condition as a1 - b1 + a2 - b2 >= k ? NO : YES on Codeforces. The tutorial text itself was basically empty, so the real work is proving why that tiny condition is not a trap.
Let
This is Alice's total score minus Bob's total score after the first two rounds. If is large, Alice is ahead; if is negative, Bob is already ahead.
Bob wants to know whether there exists some valid third round that makes him win the game. Since third-round scores must be between and , Bob's best possible score swing is achieved by
This is always legal because , so . It decreases Alice's lead by exactly . After this best-case round for Bob, the final score difference becomes
If , then , so Bob's total score is strictly larger. That immediately means Bob wins. No tiebreaker needed.
Now suppose . Even Bob's maximum possible swing leaves
so Alice still has the larger total. Bob is cooked.
The only slightly annoying case is . Then Bob can tie the total score by playing . Could he win by having more round wins? No.
Why? Each of the first two round differences is at most :
Also, every round has unequal scores, so a round Bob wins contributes a negative value to . If Bob had won either of the first two rounds, one term would be negative, and the other term could be at most , making the sum strictly less than . Therefore implies Alice won both first two rounds. In the third round Bob can win one round, but the round count becomes Alice , Bob , so Alice still wins the tiebreaker.
So Alice definitely wins exactly when . Bob has a chance exactly when
Implementation is just compute and print YES if , otherwise NO.
Complexity per test case is time and memory.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void setIO() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
}
int main() {
setIO();
int t;
cin >> t;
while (t--) {
int k, a1, b1, a2, b2;
cin >> k >> a1 >> b1 >> a2 >> b2;
int diff = (a1 - b1) + (a2 - b2);
cout << (diff < k ? "YES" : "NO") << '\n';
}
}#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void setIO() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
}
int main() {
setIO();
int t;
cin >> t;
while (t--) {
int k, a1, b1, a2, b2;
cin >> k >> a1 >> b1 >> a2 >> b2;
int diff = (a1 - b1) + (a2 - b2);
cout << (diff < k ? "YES" : "NO") << '\n';
}
}