Help me in solving CNOTE problem

My issue

Why does adding the “break;” result in WA?

My code

#include <iostream>
using namespace std;

int main() {
	// your code goes here
	int t; cin>>t;
	while (t--)
	{
	    int x, y, k, n; cin>>x>>y>>k>>n;
	    //needs x-y pages
	    int xy = x-y;
	    bool can = false;
	    for (int i = 0; i < n; i++)
	    {
	        int p, c; cin>>p>>c;
	        if (p >= xy && c <= k)
	        {
	            can = true;
	            //break;
	        }
	    }
	    can ? cout << "LuckyChef" : cout << "UnluckyChef";
	    cout << endl;
	}
	return 0;
}

Problem Link: CNOTE Problem - CodeChef

It results in WA because you are also taking input in that for loop. If you break, you will end up not taking the complete input for the current test case.

1 Like