Divide them all | CodeChef

What is wrong in my solution to the problem in the above link?
Solution below :

#include
#include
using namespace std;

int main() {
int t,n,m,x,y,i,s;
long long int j;
cin >> t;
for(i=1;i<=t;i++) {
cin >> n >> m >> x >> y;
if(n==0) {
if(m%2==0)
cout << “YES” << endl;
else
cout << “NO” << endl;
continue;
}
if(m==0) {
if(n%2==0)
cout << “YES” << endl;
else
cout << “NO” << endl;
continue;
}
if((nx+my)%2!=0) {
cout << “NO” << endl;continue;}
else {
j = (nx+my)/2;
for(s=0;s<=m;s++) {
if((j-sx)>=0 && (j-sx)%y==0) {
if(((j-s*x)/y)<=m) {
cout << “YES” << endl; break;}
else {
cout << “NO” << endl; break;}
}
else {
cout << “NO” << endl;break;
}
}
}
}
}

https://www.codechef.com/viewsolution/30790233

if you are taking mod with y check y != 0

in last loop should be run over n not over m
print “NO” in last, no value of s is possible to divide the candies equally

1 Like