Please read the new rule regarding the restriction on the use of AI tools. ×

nick2k19's blog

By nick2k19, history, 5 years ago, In English

solution explannation part-1

part-2

GITHUB link [](https://github.com/nick-mehta/codeforces/blob/master/1294A%20codeforces%20problem.cpp)

`#include <bits/stdc++.h>

using namespace std;

int main() { int t; cin>>t; int a,b,c,n;

for(int i=0;i<t;i++){
    cin>>a>>b>>c>>n;



if(a==b && b==c){
    if(n%3==0){
        cout<<"YES"<<endl;
    }
    else{
        cout<<"NO"<<endl;
    }
}
else if (a==b && a>c){
    if(n>=a-c){
        n=n-(a-c);
        if(n%3==0){
            cout<<"YES"<<endl;
        }
        else{
            cout<<"NO"<<endl;
        }
    }
    else{
         cout<<"NO"<<endl;
    }
}

 else if (a==b && a<c){
    if(n>=(2*(c-a))){
        n=n-(2*(c-a));
        if(n%3==0 ){
            cout<<"YES"<<endl;
        }
        else{
            cout<<"NO"<<endl;
        }
    }
    else{
         cout<<"NO"<<endl;
    }
}

 else if (c==b && b>a){
    if(n>=b-a){
        n=n-(b-a);
        if(n%3==0){
            cout<<"YES"<<endl;
        }
        else{
            cout<<"NO"<<endl;
        }
    }
    else{
         cout<<"NO"<<endl;
    }
}

 else if (c==b && b<a){
    if(n>=(2*(a-b))){
        n=n-(2*(a-c));
        if(n%3==0){
            cout<<"YES"<<endl;
        }
        else{
            cout<<"NO"<<endl;
        }
    }
    else{
         cout<<"NO"<<endl;
    }
}

 else if (a==c && a>b){
    if(n>=a-b){
        n=n-(a-b);
        if(n%3==0){
            cout<<"YES"<<endl;
        }
        else{
            cout<<"NO"<<endl;
        }
    }
    else{
         cout<<"NO"<<endl;
    }
}

 else if (a==c && a<b){
    if(n>=(2*(b-a))){
        n=n-(2*(b-a));
        if(n%3==0){
            cout<<"YES"<<endl;
        }
        else{
            cout<<"NO"<<endl;
        }
    }
    else{
         cout<<"NO"<<endl;
    }
}

else{
    if(a>b && a>c){
        if(n>=(a-b)+(a-c)){
            n=n-(a-b)-(a-c);
            if(n%3==0){
                cout<<"YES"<<endl;
            }else{
                cout<<"NO"<<endl;
            }
        }else{
                cout<<"NO"<<endl;
            }

    }
    else if(b>a && b>c){
        if(n>=(b-a)+(b-c)){
            n=n-(b-a)-(b-c);
            if(n%3==0){
                cout<<"YES"<<endl;
            }else{
                cout<<"NO"<<endl;
            }
        }else{
                cout<<"NO"<<endl;
            }

    }
    else if(c>a && c>b){
        if(n>=(c-b)+(c-a)){
            n=n-(c-b)-(c-a);
            if(n%3==0){
                cout<<"YES"<<endl;
            }else{
                cout<<"NO"<<endl;
            }
        }else{
                cout<<"NO"<<endl;
            }

    }

}
}

}`

  • Vote: I like it
  • 0
  • Vote: I do not like it

| Write comment?
»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

I have another solution and it's much less then your.

    vector <int> a(3);
    int n;
    cin >> a[0] >> a[1] >> a[2] >> n;
    sort(rall(a));
    n = n - (a[0] - a[1]);
    n = n - (a[0] - a[2]);
    if (n < 0) {
        cout << "NO\n";
        return;
    }
    if (n % 3 == 0) {
        cout << "YES\n";
    }
    else {
        cout << "NO\n";
    }
  • »
    »
    5 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Can you explain why did you use rall(a)?

    • »
      »
      »
      5 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it
      vector <int> a = {1, 2, 3};
      sort(rall(a));
      for (auto u : a) cout << u << " ";
      //3 2 1
      

      Now we have a, b, c, a >= b >= c

      And I supplemented b to a and c to a

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Omg god tier coder, pls enlighten me

»
5 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

The number of all coins must be devidable by 3, and none of the sisters should have more than a third of all coins beforehand.

        int sum = a + b + c + n;
        if (sum % 3 == 0 && a <= sum / 3 && b <= sum / 3 && c <= sum / 3)
                cout << "YES" << endl;
        else
                cout << "NO" << endl;