Chef Drinks Coke
All submissions for this problem are available.### Read problems statements in [Hindi](http://www.codechef.com/download/translated/COOK109/hindi/COKE.pdf), [Mandarin Chinese](http://www.codechef.com/download/translated/COOK109/mandarin/COKE.pdf), [Russian](http://www.codechef.com/download/translated/COOK109/russian/COKE.pdf), [Vietnamese](http://www.codechef.com/download/translated/COOK109/vietnamese/COKE.pdf), and [Bengali](http://www.codechef.com/download/translated/COOK109/bengali/COKE.pdf) as well. Chef went to the store in order to buy one can of coke. In the store, they offer $N$ cans of coke (numbered $1$ through $N$). For each valid $i$, the current temperature of the $i$-th can is $C_i$ and its price is $P_i$. After buying a can of coke, Chef wants to immediately start walking home; when he arrives, he wants to immediately drink the whole can. It takes Chef $M$ minutes to get home from the store. The ambient temperature outside is $K$. When a can of coke is outside, its temperature approaches the ambient temperature. Specifically, if its temperature is $t$ at some point in time: - if $t \gt K+1$, then one minute later, its temperature will be $t-1$ - if $t \lt K-1$, then one minute later, its temperature will be $t+1$ - if $K-1 \le t \le K+1$, then one minute later, its temperature will be $K$ When Chef drinks coke from a can, he wants its temperature to be between $L$ and $R$ (inclusive). Find the cheapest can for which this condition is satisfied or determine that there is no such can. ### Input - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains five space-separated integers $N$, $M$, $K$, $L$ and $R$. - $N$ lines follow. For each $i$ ($1 \le i \le N$), the $i$-th of these lines contains two space-separated integers $C_i$ and $P_i$. ### Output For each test case, print a single line containing one integer — the price of the can Chef should buy, or $-1$ if it is impossible to buy a can such that Chef's condition is satisfied. ### Constraints - $1 \le T \le 1,000$ - $1 \le N \le 100$ - $1 \le M \le 100$ - $|C_i| \le 50$ for each valid $i$ - $|K| \le 50$ - $-50 \le L \le R \le 50$ - $1 \le P_i \le 10^6$ for each valid $i$ ### Example Input ``` 2 3 2 5 4 6 1 6 2 8 8 10 3 5 10 20 30 21 20 22 22 23 23 ``` ### Example Output ``` 8 -1 ``` ### Explanation **Example case 1:** Chef should buy the second can (with price $8$), even though the first can is cheaper. If Chef bought the first can, its temperature would be $3$ when he got home, and that is outside the range $[4, 6]$. **Example case 2:** No matter which can Chef buys, when he gets home, its temperature will be less than $20$, so there is no suitable can available in the store.
|Tags||basic-math, cook109, kingofnumbers, simple, taran_1407|
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, SQL, kotlin, PERL6, TEXT, SCM chicken, PYP3, CLOJ, R, COB, FS|
Fetching successful submissions
If you are still having problems, see a sample solution here.