problem 1294A solution : collecting coins

Revision en2, by nick2k19, 2020-02-01 19:41:39

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;
            }

    }

}
}

}`

Tags #1294a, #codeforces, #div3, #solution, #math, #problem 1294a

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English nick2k19 2020-02-01 19:41:39 35 Tiny change: '50ysjY) \n[](https://youtu.be/KmRUo50ysjY)[part-2](h' -> '50ysjY) \n\n[part-2](h'
en1 English nick2k19 2020-02-01 19:40:57 3634 Initial revision (published)