CNOTE - Editorial

Where Mycode going wrong it is showing WA as well as TLE.
here is my code:

#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
int x,y,n,k,ans=0;
cin>>t;
while(t–){
ans=0;
cin>>x>>y>>n>>k;
int page[n],cost[n];
//cout<<n<<endl;
for(int i=0;i<n;i++){
cin>>page[i]>>cost[i];
}
for(int i=0;i<n;i++){
if((page[i]>=(x-y))&&(cost[i]<=k)){
ans=1;
break;
}
}
if(ans==1)
cout<<“LuckyChef”<<endl;
else
cout<<“UnluckyChef”<<endl;
}
return 0;
}

You’re reading the input in the wrong order: look at the Input section of the Problem statement more carefully :slight_smile:

1 Like

T=int(input())
for i in range(T):
X,Y,K,N=map(int,input().split())
p=[]
c=[]
flag=1
for j in range(N):

           p,c=map(int,input().split())
           if(c<=K and p+Y>=X):
                   flag=0
    if(flag==0):
            print('LuckyChef')
    else:
            print('UnluckyChef')
	public static void main (String[] args) throws java.lang.Exception
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int t = Integer.parseInt(br.readLine());

		String mainInput[];
		int no_of_pages_required;
		int no_of_pages_left;
		int money;
		int no_of_notebooks;

		String notebook_details[];
		int pages;
		int price;
		boolean flag;
		for(int i = 0; i<t; i++) {

			flag = true;
			//assignment of inputs
			mainInput = br.readLine().split("\\s+");
			no_of_pages_required = Integer.parseInt(mainInput[0]);
			no_of_pages_left = Integer.parseInt(mainInput[1]);
			money = Integer.parseInt(mainInput[2]);
			no_of_notebooks = Integer.parseInt(mainInput[3]);


			for(int j = 0; j<no_of_notebooks; j++) {
			//assignment of notebook_mdetails
			notebook_details = br.readLine().split(" ");
			pages = Integer.parseInt(notebook_details[0]);
			price = Integer.parseInt(notebook_details[1]);

				if(pages >= no_of_pages_required - no_of_pages_left && price <= money) {
					System.out.println("LuckyChef");
					flag = false;
					break;
				}
			}

			if(flag)
				System.out.println("UnluckyChef");
		}
        }

I am getting Runtime error - NZEC in this. Can’t get it to working :confused:

Same as this guy: CNOTE - Editorial - #33 by ssjgz

1 Like

Alright. Checking into it right away.

1 Like

I’ve just edited that post as the testcase contained some extra whitespace that caused your solution to choke, so make sure you’re using the updated testcase to debug :slight_smile:

2 Likes

Got it working. I really need to start focusing on the little things. Thanks for the help!

1 Like

Exact replica for your Python 2 code in Python 3 does not work. I mean it gives runtime error. Please help!

T = int(input())
for i in range(T):
X,Y,K,N = map(int, input().split(’ ‘))
books = []
for k in range(N):
p,c = map(int, input().split(’ '))
books.append((p,c))
for p,c in books:
if p>=(X-Y) and c<=K:
print(‘LuckyChef’)
break
else:
print(‘UnluckyChef’)

Figured out the solution myself.
I think there was extra whitespace in test cases…so added input().strip().split(’ ') and it is working now!!

1 Like

#include
using namespace std;

int main() {
int i,t,x,y,k,n,p,c,j=0;
cin>>t;
for(int i=0;i<t;i++)
{cin>>x>>y>>k>>n;
bool found=false;
for(int i=0;i<n;i++)
{cin>>p>>c;
if(p>=x-y&&c<=k)
{found=true;
break;
}}
cout<<(found?“LuckyChef”:“UnluckyChef”)<<endl;}
return 0;
}
Please help me.
When i run the program it runs successfully but on submission shows wrong answer.
Can somebody please point out the mistakes.

Please either format your code or (better!) link to your submission - the forum software has mangled it and it won’t compile! :slight_smile:

Edit:

While we’re waiting - make sure your code gets the correct answer for this testcase.

Very well organized and over simplified tutorial ! Exactly what a newbie like me needs ! :slight_smile:
GREAT WORK!

https://www.codechef.com/viewsolution/37036315
This solution is giving runtime error because of break statement in the if block. Please tell me the reason behind it.

Try with this testcase:

and all should become clear :slight_smile:

2 Likes

Thanks @ssjgz :smiley:

1 Like

#include
using namespace std;

int main() {
long long t,poet,chefpage,chefK,n,pageN,costN;
cin>>t;
while(t–){
bool f=false;
cin>>poet>>chefpage>>chefK>>n;
while(n–){
cin>>pageN>>costN;
if(pageN>=poet-chefpage && costN<=chefK){
f=!f;
break;
}
}
if(f){
cout<<“LuckyChef”<<endl;
}else{
cout<<“UnluckyChef”<<endl;
}
}
return 0;
}

The only difference I see in the array for cost and pages. int P[111111];
int C[111111]; how does This give the correct answer please explain if you get to know.

The only difference I see in the array for cost and pages. int P[111111];
int C[111111]; how does This give the correct answer please explain if you get to know.

very good editorial.
Thanks author