Please find bugs and explain

My issue

Code is perfectly working but it’s showing wrong answer

My code

#include <iostream>
using namespace std;

int main() {
	// your code goes here
	int t,h,x,y ;
	bool a=true;
	bool b=false;
	cin>>t;
	while (t--){
	    cin >>h>>x>>y ;
	    for(int i=0;i>=0;i++){
	    if (((h+y)-x)+y<=x){
	        cout <<a<<endl;
	        break;
	    }
	    else{
	        cout <<b<<endl;
	       break;
	    }
	    }
	}
	return 0;
}

Problem Link: CodeChef: Practical coding for everyone

@amnkhxn
The logic i used in this question was like this;

Monster has H health points, it gains Y (Rate of gain) before a hit and loses X (Rate of loss) after every hit.

If the rate of health loss is greater than rate of health gain, it can be defeated.

Case 1: Rate of gain is more than or equal to rate of loss. (Y>=X).

Here, it is impossible to defeat the monster as its health point will either always be increasing or be constant.

Case2: Rate of gain is lower than rate of loss. (Y<X) or ((X-Y)>0)

Here, the monster will keep losing some health point at every strike and after a while its health H will reach zero. Thus, it is possible to defeat the monster.

if(y>=x):
        print(0)
else:
        print(1)

To add to this, in your if condition, you are using a break statement which will force the control out of loop, so not all test cases would be checked.

2 Likes