Chef and Notebooks Codechef Solution

Chef likes to write poetry. Today, he has decided to write a X pages long poetry, but unfortunately his notebook has only Y pages left in it. Thus he decided to buy a new CHEFMATE notebook and went to the stationary shop. Shopkeeper showed him some N notebooks, where the number of pages and price of the ith one are Pi pages and Ci rubles respectively. Chef has spent some money preparing for Ksen’s birthday, and then he has only K rubles left for now.

Chef wants to buy a single notebook such that the price of the notebook should not exceed his budget and he is able to complete his poetry.

Help Chef accomplishing this task. You just need to tell him whether he can buy such a notebook or not. Note that Chef can use all of the Y pages in the current notebook, and Chef can buy only one notebook because Chef doesn’t want to use many notebooks.

Input

The first line of input contains an integer T, denoting the number of test cases. Then T test cases are follow.

The first line of each test case contains four space-separated integers XYK and N, described in the statement. The ith line of the next N lines contains two space-separated integers Pi and Ci, denoting the number of pages and price of the ith notebook respectively.

Output

For each test case, Print “LuckyChef” if Chef can select such a notebook, otherwise print “UnluckyChef” (quotes for clarity).

• 1 ≤ T ≤ 105
• 1 ≤ Y < X ≤ 103
• 1 ≤ K ≤ 103
• 1 ≤ N ≤ 105
• 1 ≤ Pi, Ci ≤ 103

• Sum of N over all test cases in one test file does not exceed 104.

• Sum of N over all test cases in one test file does not exceed 106.

Input
3
3 1 2 2
3 4
2 2
3 1 2 2
2 3
2 3
3 1 2 2
1 1
1 2

Output
LuckyChef
UnluckyChef
UnluckyChef

Explanation

Example case 1. In this case, Chef wants to write X = 3 pages long poetry, but his notebook has only Y = 1 page. And his budget is K = 2 rubles, and there are N = 2 notebooks in the shop. The first notebook has P1 = 3 pages, but Chef cannot buy it, because its price is C1 = 4 rubles. The second notebook has P2 = 2 pages, and its price is C2 = 2 rubles. Thus Chef can select the second notebook to accomplish the task. He will write 1 page of poetry in the old notebook, and 2 page of poetry in the new notebook.

Example case 2. Chef cannot buy any notebook, because the prices exceed the Chef’s budget.

Example case 3. No notebook contains sufficient number of pages required to write poetry.

Chef and Notebooks   – CodeChef Solution in JAVA

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 IOException{
BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(System.out));
while(t-->0)
{
int pages=Integer.parseInt(s)-Integer.parseInt(s);
int money=Integer.parseInt(s);
int n=Integer.parseInt(s);
boolean flag=true;
for(int i=0;i<n;i++)
{
int page=Integer.parseInt(s);
int cost=Integer.parseInt(s);
if(cost<=money && page>=pages && flag)
{
bw.write("LuckyChef\n");
flag=false;
}
}
if(flag)
bw.write("UnluckyChef\n");
}
bw.flush();
}
}

Chef and Notebooks- CodeChef Solution in CPP

#include <iostream>
#include<vector>
using namespace std;
void solve(){
int X,Y,K,N;
cin>>X>>Y>>K>>N;
vector<pair<int,int>> dukan;
for(int i=0;i<N;i++){
int pages;
int cost;
cin>>pages>>cost;
pair<int,int>mypair=make_pair(pages,cost);
dukan.push_back(mypair);
}
for(int i=0;i<dukan.size();i++){
if(dukan[i].first >=(X-Y) and dukan[i].second<=K){
std::cout << "LuckyChef" << std::endl;
return;
}
}
cout<<"UnluckyChef"<<endl;
}
int main() {
int test;
cin>>test;
while(test--){
solve();
}
return 0;
}

Chef and Notebooks  -CodeChef Solution in Python

try:
for _ in range(0,int(input())):
x,y,k,n = map(int,input().split())
temp = False
left = x-y
for i in range(0,n):
p,c = map(int,input().split())
#print(p,y,c,k)
if p >= left and c <= k:
temp = True
if temp:
print("LuckyChef")
else:
print("UnluckyChef")
except:
pass

Disclaimer: The above Problem (Chef and Notebooks) is generated by CodeChef but the solution is provided by Codeworld19.This tutorial is only for Educational and Learning purpose.