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.
#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
]$ ./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;
}
Yep - is that the correct answer?
But I can’t pass any Codechef tests
You didn’t answer my question
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
?
Correct Answer should be
LuckyChef
LuckyChef
right ?
but my answer is
LuckyChef
UnluckyChef
Am I right ?
Yep - so now you have a nice, 100% reproducible testcase, lovingly handcrafted to highlight the flaw in your code - get debugging
#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 …
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
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
Alright. Checking into it right away.