CNOTE - Editorial

Now I get it. Thanks !

Here’s a more pythonic code golf:

for _ in xrange(input()):
    X, Y, K, N = map(int, raw_input().split())
    print ["UnluckyChef", "LuckyChef"][any(P >= X - Y and C <= K for P, C in [map(int, raw_input().strip().split()) for i in xrange(N)])]
2 Likes

When you post code, you should try indenting all your code four spaces, so that it renders properly as code.

because you are breaking the loop after getting result. you are not collecting all the input data. hence getting the wrong answer. remove break statement and you would get the correct answer.

i get a wrong answer when i use this snippet to take an integer input
int fastscan()
{
int c = gc();
int x = 0;
for (; (c>47 && c<58); c=gc())
x = x *10 + c - 48;
return x;
}

but when i used cin instead of this snippet my solution gets accepted.

@kevinsogo
Total number of test cases =10^5
Total Iterations in subtask1=10^9
subtask2=10^11

But we are allowed only 10^8 iterations , so how this code is running, can anyone help??

thanks for the message this helped me a lot,kudos!

Following is my CPP code. what am I doing wrong?
Not even first subtask is correct.

#include <iostream>
using namespace std;

int main() {
	int t, x, y, k, n, pi, ci;
	bool found;
	cin >> t;
	while(t--){
	    cin >> x >> y >> k >> n;
	    found = (y >= x) ? true: false;  // current book is enough.
	    while((n--) && (!found)){
	        cin >> pi >> ci;
	        if((ci <= k) && (pi >= (x - y))){
	            found = true;
	        }
	    }
	    if(found)
	        cout << "LuckyChef" << endl;
	    else 
	        cout << "UnluckyChef" << endl;
	}
	return 0;
}
#include <iostream>
using namespace std;

int main() {
	int t, x, y, k, n, pi, ci;
	bool found;
	cin >> t;
	while(t--){
	    cin >> x >> y >> k >> n;
	    found = (y >= x) ? true: false;  // current book is enough.
	    while((n--) && (!found)){
	        cin >> pi >> ci;
	        if((ci <= k) && (pi >= (x - y))){
	            found = true;
	        }
	    }
	    if(found)
	        cout << "LuckyChef" << endl;
	    else 
	        cout << "UnluckyChef" << endl;
	}
	return 0;
}
#include <iostream>
using namespace std;
int main() {
	 int T;
	cin>>T;
	for(int i = 0; i < T; i++){
	    int X,Y,K,N;
 	    cin >> X >> Y >> K >> N;
        bool luck = false;
        for(int j =0; j < K;j++){
           int p,q;
            cin>>p>>q;
            if(q <= K & p >= (X-Y)){
                luck = true;
            }
         }
        if(!luck){
             cout<<"UnluckyChef"<<' ';
        }else{
             cout<<"LuckyChef"<<' ';
        }
    }
    return 0;
  }

i cant understand whats wrong with this code.

1 Like

#include <stdio.h>
int main(void) {
// your code goes here
int i,j,k,l;
int nooftestcases;
scanf("%d",&nooftestcases);
for(i=0;i<nooftestcases;i++){
int storypages,existingpages,pagesrequired,moneyleft,noofbooks;
scanf("%d",&storypages);
scanf("%d",&existingpages);
//printf("%d\n",pagesrequired);
scanf("%d",&moneyleft);
scanf("%d",&noofbooks);
//pagesrequired = storypages - existingpages;
//printf("%d\t%d",moneyleft,noofbooks);
for(j=0;j<noofbooks;j++){
int bookpages,cost;
scanf("%d",&bookpages);
scanf("%d",&cost);
if(bookpages>=storypages - existingpages && moneyleft>=cost){
printf(“LuckyChef\n”);
break;
}
bookpages;cost;
}
if(j==noofbooks){
printf(“UnluckyChef\n”);
}
}
return 0;
}

can someone pls look into the code and tell what’s wrong

#include <iostream>

using namespace std;

int main(int argc, char *arg[]) {
    long int T, X, Y, K, N;

    cin >> T;
    long int t = 0, n, pi, ci, req_pages;
    bool found;

    while (t < T) {
        cin >> X >> Y >> K >> N;

        req_pages = X-Y;
        n = 0;
        found = false;
        while (n < N) {
            cin >> pi >> ci;
            if ((req_pages <= pi) && (ci <= K)) {
                found = true;
                break;
            }
            ++n;
        }

        cout << (found ? "LuckyChef" : "UnluckyChef") << '\n';
        ++t;
    }

    return 0;

}

I don’t see anything wrong with the program and yet I’m unable to get the right …

Consider the testcase:

2
2 1 5 2
1 1
100 5
2 1 1 1
1 1
2 Likes
]$ ./test < input.txt
LuckyChef
UnluckyChef


#include <iostream>

using namespace std;

int main(int argc, char *arg[]) {
    size_t T, X, Y, K, N, t, n, pi, ci, req_pages;
    bool found;

    t = 0;
    cin >> T;
    while (t < T) {
        cin >> X >> Y >> K >> N;

        req_pages = X-Y;
        n = 0;
        found = false;
        while (n < N) {
            cin >> pi >> ci;
            if ((req_pages <= pi) && (ci <= K)) {
                found = true;
                break;
            }
            ++n;
        }

        cout << (found ? "LuckyChef" : "UnluckyChef") << endl;
        ++t;
    }

    return 0;

}
1 Like

Yep - is that the correct answer?

But I can’t pass any Codechef tests :slight_smile:

You didn’t answer my question :slight_smile:

Edit:

To be more explicit:

What is the answer to

1
2 1 5 2
1 1
100 5

?

What is the answer to

1
2 1 1 1
1 1

?

So what should the answer be for

2
2 1 5 2
1 1
100 5
2 1 1 1
1 1

?

1 Like

Correct Answer should be

LuckyChef
LuckyChef

right ?

but my answer is

LuckyChef
UnluckyChef

Am I right ?

1 Like

Yep - so now you have a nice, 100% reproducible testcase, lovingly handcrafted to highlight the flaw in your code - get debugging :slight_smile:

Two months late, but yours fails on the same testcase as @onkag2, and for the same reason :slight_smile:

#include <iostream>

using namespace std;

int main(int argc, char *arg[]) {
    size_t T, X, Y, K, N, t, n, pi, ci, req_pages;
    bool found;

    t = 0;
    cin >> T;
    while (t < T) {
        cin >> X >> Y >> K >> N;

        req_pages = X-Y;
        n = 0;
        found = false;
        while (n < N) {
            cin >> pi >> ci;
            if ((req_pages <= pi) && (ci <= K))
                found = true;
            ++n;
        }

        cout << (found ? "LuckyChef" : "UnluckyChef") << endl;
        ++t;
    }

    return 0;

}

Simple mistake while reading the inputs, but spent a whole day debugging … finally debugged it using cout to print ci, pi, req_pages.

All tests passed …

Fix was to allow inner while loop to complete before re-reading the next test case … X, Y, K, N …

1 Like