Help me in solving EQUALCOIN problem

My issue

why is this logic not working . atlast if my value is even i can distribute it to both kids evenly so what’s the issue here?

My code

#include<bits/stdc++.h>
using namespace std;
int main() {
    int t;
    cin>>t;
        while(t--){
            long long int x,y;
            cin>>x>>y;
            long long int sum=(x*1)+(y*2);
            if(sum%2!=0){
                cout<<"NO"<<endl;
            }
            else{
                cout<<"YES"<<endl;
            }
        }
	return 0;
}

Problem Link: EQUALCOIN Problem - CodeChef

if ((sum% 2 == 0) && ((x % 2 == 0 && x > 0 && y % 2 != 0) || (y % 2 == 0))) 

Two possible cases for this to work:

If y is odd, x has to be even and larger than zero (and the sum is even)
OR
If y is even (and the sum is even)

@anidave09
plzz refer my c++ code for better understanding of the logic.
I have done it in much simpler way.

#include <iostream>
using namespace std;

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--)
	{
	    int x,y;
	    cin>>x>>y;
	    if(y%2==0)
	    {
	        if(x%2==0)
	        cout<<"YES";
	        else
	        cout<<"NO";
	        cout<<endl;
	    }
	    else
	    {
	        if(x%2==0&&x>=2)
	        cout<<"YES";
	        else
	        cout<<"NO";
	        cout<<endl;
	    }
	}
	return 0;
}
1 Like