Full Barrier Alchemist

All submissions for this problem are available.
Edward Elric is chasing after Scar. To stop Edward, Scar creates $N$ barriers in the way, numbered from $1$ to $N$. Each barrier Scar created is either one of the following two types.  Type 1 barrier  This barrier start from a height $X$ above the ground and extend till the sky.  Type 2 barrier  This barrier start from the ground and extend up to height $X$ above the ground. ![](https://codechef_shared.s3.amazonaws.com/download/HYC/External_contest_i... =500x500) The height of Edward is $H$ units and he has an alchemic life force of $L$ units. Moreover, he can duck by $Y_{1}$ units and jump by height $Y_{2}$ units (as explained in the figures). He starts crossing barriers in sequence, starting from barrier $1$ till the barrier $N$. Whenever he can't pass a barrier by ducking or jumping (considered passed even when the barrier just touches him), he uses Alchemy to break the barrier. However, this costs him a single unit of his alchemic life force. If after breaking a barrier no life force is left, Edward gets completely exhausted, unable to pass that barrier. How many barriers can Edward cross? And remember never to call him a pipsqueak if his height is too short! ### Input:  The first line contains $T$, the number of test cases. Then the test cases follow.  For each test case, the first line contains five integers $N$, $H$, $Y_{1}$, $Y_{2}$ and $L$.  The next $N$ lines, each contain two integers $t_{i}$ and $X_{i}$ for the $i^{th}$ barrier where $t_{i} = 1$ denotes a Type 1 Barrier and $t_{i} = 2$ denotes a Type 2 barrier. ### Output: For each test case print a single line containing the number of barriers Edward can pass. ### Constraints  $1 \leq T\leq 100$  $1 \leq N\leq 10^{3}$  $2 \leq H\leq 10^{3}$  $1 \leq Y_{1} < H$  $1 \leq Y_{2} \leq 10^{3}$  $1 \leq L \leq N$  $1 \leq t_{i} \leq 2$  $1 \leq X_{i}\leq 10^{3}$ ### Sample Input: ``` 3 6 5 1 2 3 2 2 2 1 1 10 2 8 2 4 1 2 1 4 2 5 1 2 6 6 5 1 2 3 2 2 2 1 1 10 2 8 2 4 1 6 ``` ### Sample Output: ``` 5 0 6 ``` ### Explanation: **Test Case 1:** Given $N = 6$, $H = 5$, $Y_{1} = 1$, $Y_{2} = 2$ and $L = 3$. He passes the first three barriers by either ducking or jumping. He uses alchemic life force for breaking $4^{th}$, $5^{th}$ and $6^{th}$ barrier because he cannot pass them by either jumping or ducking. He gets exhausted after breaking the $6^{th}$ barrier and is unable to pass it. So, in total he passes $5$ barriers.Author:  sachin_yadav 
Editorial  https://discuss.codechef.com/problems/PIPSQUIK 
Tags  cakewalk, dcod2019, sachin_yadav 
Date Added:  19102019 
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 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 