Sir ,
let g=gcd(w,d);
my first condition is same i.e
if(p%g!=0) cout<<"-1";
After this I thought to use dophantine equation as follows:
I found x0 & y0 by extended euclid algorithm as discussed in the above course.
Now we can have infinitely many solutions therefore,
x=x0+(b/g)*t; y=y0 -(a/g)*t;
and I also know x+y+z=n
hence I can also say 0<=x+y<=n;
and simulntaneously x>=0 and y>=0 .
Now in the end I have 3 inequalities,
1)x>=0, 2)y>=0 and 3) 0<=x+y<=n;
solving these three inequalities will give me a “t” and then substituting it I can get x,y,z. I have thoroughly checked my inequalities condition and I ask whether the above method is right or wrong because I am getting wrong answer on codeforces.