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

**Task**

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 **i**^{th} one are **P _{i}** pages and

**C**rubles respectively. Chef has spent some money preparing for Ksen’s birthday, and then he has only

_{i}**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 **i**^{th} line of the next **N** lines contains two space-separated integers **P _{i}** and

**C**, denoting the number of pages and price of the

_{i}**i**

^{th}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 ≤ 10**^{5}**1 ≤ Y < X ≤ 10**^{3}**1 ≤ K ≤ 10**^{3}**1 ≤ N ≤ 10**^{5}**1 ≤ P**_{i}, C_{i}≤ 10^{3}

**Subtask 1: 40 points**

- Sum of
**N**over all test cases in one test file does not exceed**10**.^{4}

**Subtask 2: 60 points**

- Sum of
**N**over all test cases in one test file does not exceed**10**^{6}

**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 **P _{1} = 3** pages, but Chef cannot buy it, because its price is

**C**rubles. The second notebook has

_{1}= 4**P**pages, and its price is

_{2}= 2**C**rubles. Thus Chef can select the second notebook to accomplish the task. He will write

_{2}= 2**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() { // your code goes here 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') # cook your dish here

**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"); } } // your code goes here } }

**Disclaimer: **The above Problem **(Chef and Notebooks)** is generated by **CodeChef **but the Solution is Provided by **CodingBroz**. This tutorial is only for **Educational** and** Learning** Purpose.