CNOTE - Editorial

basic-prog
cakewalk
cnote
editorial
march15

#4

great editorial :slight_smile:


#5

Can anybody tell me whats wrong with my code?


#6

@kevinsogo

Great work my friend. :slight_smile:


#7

Python code, you say? Here’s mine.

for _ in xrange(input()):
    X, Y, K, N = map(int, raw_input().split())
    print ["UnluckyChef", "LuckyChef"][min(1, len(filter(lambda b: b[0] <= 0 and b[1] >= 0, [[x - y for x, y in zip([X - Y, K], map(int, raw_input().split()))] for __ in xrange(N)])))]

I know it wasn’t code golf or anything like that but boy it was fun to squeeze it into 3 lines. xD


#8

Awesome Editorial! keep it up. looking forward to more editorials :smiley:


#9

I don’t understand “it immediately breaks out of the loop, so it fails to read the next case properly”. How breaking out would cause problem for the next case.


#10

In this example, even if there is a better solution, it wouldn’t be looked into. only the first solution that matches is taken. Is this the objective? obviously if there is a better combination of price and pages that satisfies the solution, but more optimised (in terms of price, say) then it wouldn’t be printed. Maybe I assumed that the optimised should be printed. Thanks!

ps. Great Editorial with multi-language implementation.


#11

great explanation


#12

My solution is getting WA for Sub-task 2, Task#4, can anyone suggest any edits?

t = int(input()) for i in range(t): x, y, k, n = map(int, input().split()) l = [0]*n cost = [1000]*n j=0 for j in range(n): l = list(map(int, input().split())) if l[0]>=(x-y): cost[j] = l[1] if min(cost)<=k: print("LuckyChef") else: print("UnluckyChef")


#13

When I am running my code on ideone compiler ,the output is coming correct.But on running through it shows wrong answer.Can someone explain how to do subtasks?I made variable N and T long int still my answer is not getting accepted


#14

How to solve it, if we are allowed to buy multiple notebooks instead of just one? Do we need to need to use Knapsack DP?


#15

package easyLevel;

import java.util.Scanner;

public class ChefNNotebooks_CNOTE {

public static void main(String args[]){
	
	Scanner sc = new Scanner(System.in);
	
	int T = sc.nextInt();
	
	while(T > 0){
		
		String result = "UnluckyChef";
		int X = sc.nextInt();
		int Y = sc.nextInt();
		int K = sc.nextInt();
		int N = sc.nextInt();
		
		while(N > 0){
			
			int P = sc.nextInt();
			int C = sc.nextInt();
			
			if(C <= K && P >= X-Y){
				result = "LuckyChef";
				break;
			}
			
			N--;
		}
		
		System.out.println(result);
		T--;
	}
}

}

gettinh WA, not sure why


#16

@kevinsogo:

After the implementaion on C++ code, in the statement "Note that we used ’
’ instead of endl, because endl forces a flush, " what is flush and when can we know flush occured in the program (or) not?


#17

Love your approach, multiple examples in multiple language !!!


#18

There is a problem because you broke out of the loop too early while reading N pairs of integers (Pi, Ci). This means that the next Pi will be interpreted as the X of the next case, the Ci will be interpreted as the Y, and so on. Or if you are processing the input line by line, then you might get runtime error, because you were expecting four integers (X, Y, K, N) but only got two (Pi, Ci).

The explanation has been updated to explain this.


#19

@saiavinashiitr a link explaining “flush” has been added. The idea is that when you do cout << something, the something isn’t necessarily immediately printed to the console/stdout. cout usually buffers them first, and then prints by batch, because printing something to the console is slow.

You call “flush” when you want it to be printed immediately (just like flushing a toilet). However, endl always forces a flush, causing unnecessary overhead in printing. By using ' ', there is no flush, so it’s faster.


#20

@kevinsogo : Thank you, and your way of pointing out the common mistakes is nice and overall u made this editorial awesome :slight_smile:


#21

Now I get it. Thanks !


#22

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)])]

#23

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