Nasser's Card Game#12347

Nasser's Card Game (Editorial)

Problem Author:

Mohammad Nasser (MOAGEZA)

Prepared by:

Mohammad Nasser (MOAGEZA)

Edited by:

Hasan Saleh (MathModel)

Solution

General Idea: There are exactly red cards in total. If the three players report , , and red cards, then the fourth player must have:

7 - (a + b + c)

red cards.

The game must restart if **any** player has at least red cards. Therefore, we simply compute the maximum among the four players:

\max(a, b, c, 7 - (a + b + c))

If this value is , restarting is guaranteed; otherwise, it is not required.

The solution runs in time per test case.

#include <bits/stdc++.h>
using namespace std;

void solve(){
    int a,b,c;
    cin>>a>>b>>c;
    int mx = max({a,b,c,7-(a+b+c)});
    if(mx>=5) cout<<"YES";
    else cout<<"NO";
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t;
    cin>>t;
    while(t--){
        solve();
        cout<<'\n';
    }
}