Coin Piles problem from cses

Hi all
I am trying to solve this problem but unable to find the solution.
Any kind of hint would be great.
https://cses.fi/problemset/task/1754/

This is what I did:
Try removing coins from bottom, It’s more intuitive that way.

if(a<b)swap(a,b);
if(a>2*b){
    cout<<"NO\n";
}else{
    a%=3,b%=3;
    if(a<b)swap(a,b);
    if((a==2 && b==1) || (a==b && b==0)){
        cout<<"YES\n";
    }else{
        cout<<"NO\n";
    }
}
1 Like

I really wish they had solutions for cses, It has really good problems.

got your idea thanks.
I was also thinking this way but couldn’t come with a%=3,b%=3; this step.

1 Like

Here is my solution.

  if(a<b) swap(a,b);

  if(a>2*b) 
  {
     cout<<"NO" << endl;
     return 0;
   }

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