# Chef and Notebooks | CodeChef Solution

Hello coders, today we are going to solve Chef and Notebooks CodeChef Solution whose Problem Code is CNOTE.

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 Format

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Â X,Â Y,Â KÂ 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 Format

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

## Constraints

• 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

Sample 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``````

Sample 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.

## Solution – Chef and Notebooks

### C++

```#include <iostream>
using namespace std;

int main() {
int t;
cin>>t;
while(t--){
int x,y,k,n;
cin>>x>>y>>k>>n;
y=x-y;
int flag=0;
while(n--){
int p,i;
cin>>p>>i;
if(y<=p && i<=k) {
flag=1;
//break;
}
}
if(flag) cout<<"LuckyChef"<<endl;
else cout<<"UnluckyChef"<<endl;
}
return 0;
}
```

### Python

```T=int(input())
for i in range(T):
X,Y,K,N=map(int,input().split())
x=[]
for j in range(N):
Pj,Cj=map(int,input().split())
x.append([Pj,Cj])
for l in x:
if l[0]>=(X-Y) and l[1]<=K:
print('LuckyChef')
break
else:
print('UnluckyChef')
```

### Java

```/* package codechef; // don't place package name! */

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
{
Scanner s=new Scanner(System.in);
int cases=s.nextInt();
int t=0;
while(cases-- >0)
{
t=0;
int sub[] = new int[4];
for(int a=0;a<4;a++)
{
sub[a] = s.nextInt();
}
int value[][] = new int[2][sub[3]];
for(int k=0;k<sub[3];k++)
{
value[0][k]=s.nextInt();
value[1][k]=s.nextInt();
}

for(int i=0;i<sub[3];i++)
{
if(value[0][i]>=(sub[0]-sub[1]) && sub[2]>=value[1][i])
{
t=1;
break;
}
}
if(t==1)
{
System.out.println("LuckyChef");
}
else{System.out.println("UnluckyChef");
}
}