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.
A red card always suspends exactly one player. There is no clever way to make one red card suspend two people, sadly.
After using all red cards, you already have suspended players. The only question is how many extra players can be suspended using yellow cards.
One yellow card alone never suspends anyone. Two yellow cards can suspend one player, so yellow-only suspensions are worth yellows each.
You cannot create more yellow-only suspended players than there are players who did not already get red-card suspended. That limit is .
So the answer is
The key is to not overthink the card order. This is an 800, so if it looks like a trap, the trap is probably your brain trying to invent DP.
What does a red card do?
Every red card suspends exactly one player. Also, once that player is suspended, they leave and cannot receive more cards.
So with red cards, exactly players can be suspended by red cards. Since the statement guarantees , these red cards can always be assigned to distinct players.
That gives us a baseline:
What can yellow cards add?
A player is suspended by yellow cards only after receiving yellow cards. Therefore, every additional suspension from yellows costs exactly yellow cards.
With yellow cards, the raw number of yellow-card suspensions is at most:
But there is also a player-count limit. The red-card suspended players are already counted. If we want extra suspensions from yellow cards, those need to be different players. There are only:
players left who can contribute new suspensions.
So the number of extra suspensions from yellow cards is:
Add the red-card suspensions back:
Why this is always achievable
Take players and give each one a red card. They are suspended.
Then take up to of the remaining players and give each of them yellow cards. Each of those players is suspended too.
If there are leftover yellow cards, they can be placed harmlessly before some red cards or as single yellows on unsuspended players. The input condition guarantees the card totals are physically possible, so no weird impossible-card nonsense breaks the construction.
So the formula is not just an upper bound. It is tight.
#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 n, y, r;
cin >> n;
cin >> y >> r;
cout << r + min(y / 2, n - r) << '\n';
}
return 0;
}#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 n, y, r;
cin >> n;
cin >> y >> r;
cout << r + min(y / 2, n - r) << '\n';
}
return 0;
}