my python code
t=int(input())
for _ in range(t):
x,y,k,n=[int(a) for a in input().split()]
want=x-y
re="UnluckyChef"
for l in range(n):
p,c=[int(a) for a in input().split()]
if p>=want and c<=k:
re="LuckyChef"
print(re)
my python code
t=int(input())
for _ in range(t):
x,y,k,n=[int(a) for a in input().split()]
want=x-y
re="UnluckyChef"
for l in range(n):
p,c=[int(a) for a in input().split()]
if p>=want and c<=k:
re="LuckyChef"
print(re)
a=int(input())
for i in range(a):
x,y,k,n=map(int,input().split())
for j in range(n):
p,c=map(int,input().split())
if y+p>x & k>=c:
print("LuckyChef")
else:
print("UnluckyChef")
How is this even wrong it works in Run section but not in submit did I forgot something?
Your code can print âLuckyChefâ and âUnluckyChefâ multiple times for a particular i (i.e test case). But we are required to output either âLuckyChefâ or âUnluckyChefâ (exactly one of them) once for each test case.
So, correct logic would be to maintain a flag fl := 0 which is handled as follows:
if (y + p >= x and k >= c) :
fl = 1
After processing all the (p_i, c_i)'s we can print based on fl.
I donât know why my implement doesnt work, any suggestion, thank yoiu
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Codechef.FastIO io = new Codechef().new FastIO();
int tc = io.nextInt();
for(int tce=0;tce<tc; tce++){
int x = io.nextInt();
int y = io.nextInt();
int k = io.nextInt();
int n = io.nextInt();
boolean found = false;
for(int i = 0; i<n; i++){
int pi = io.nextInt();
int ci = io.nextInt();
if (pi >= x - y && ci <= k) {
found = true;
break;
}
}
System.out.println(found ? "LuckyChef" : "UnluckyChef");
}
io.close();
}
class FastIO extends PrintWriter {
private InputStream stream;
private byte[] buf = new byte[1 << 16];
private int curChar;
private int numChars;
// standard input
public FastIO() { this(System.in, System.out); }
public FastIO(InputStream i, OutputStream o) {
super(o);
stream = i;
}
// file input
public FastIO(String i, String o) throws IOException {
super(new FileWriter(o));
stream = new FileInputStream(i);
}
// throws InputMismatchException() if previously detected end of file
private int nextByte() {
if (numChars == -1) {
throw new InputMismatchException();
}
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars == -1) {
return -1; // end of file
}
}
return buf[curChar++];
}
// to read in entire lines, replace c <= ' '
// with a function that checks whether c is a line break
public String next() {
int c;
do {
c = nextByte();
} while (c <= ' ');
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = nextByte();
} while (c > ' ');
return res.toString();
}
public int nextInt() { // nextLong() would be implemented similarly
int c;
do {
c = nextByte();
} while (c <= ' ');
int sgn = 1;
if (c == '-') {
sgn = -1;
c = nextByte();
}
int res = 0;
do {
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res = 10 * res + c - '0';
c = nextByte();
} while (c > ' ');
return res * sgn;
}
public double nextDouble() { return Double.parseDouble(next()); }
}
}