EIUASSEMBLY - Assembly line


The Alternate Control Machine (ACM) Factory has a large assembly line to make a type of product. The assembly has N robots (R1, R2 ... RN) working sequentially. That means a semi-finished product moves from robot R1, to R2, then to R3 ... to RN. Each robot adds a component to the product. Each robot can complete its own job in Pi products per one hour.

The company has a budget of M VNĐ to improve productivity for the entire assembly. As a product director, you know that robot Ri needs to invest Mi VNĐ to contribute to the production of one more product per hour. You have to optimize the amount of money to invest to each robot to produce maximum number of products per hour.

Input

The first line of input contains one integer T (1 ≤ T ≤ 10) - the number of test cases.

Then T test cases are given as follows:

  • The first line of each test case contains an integer N (1 ≤ n ≤ 105) and an integer M (0 ≤ M ≤ 1012) – the number of robots and the budget
  • Line i-th of the next N lines contains two integers Pi (1 ≤ Pi ≤ 109) and Mi (1 ≤ Mi ≤ 109) – information of the robot i-th

Output

For each test case, output in one line the maximum number of products the assembly can make after investing at most M VNĐ.

Example

Input:
1
3 7
1 2
2 3
3 1

Output:
3

Hint: You should check for the case: company budget is 0, or cannot upgrade any robot at all. This is the visualization explain why you should check if you use binary search to solve.


hide comments
lt: 2016-06-01 08:35:59

I have no idea why the hell I'm getting WA, my code passes all the tests that I generated randomly, still submitting the solution gives immediate WA. Please, tell me what can be the flaw? submission id: 17026337

Ha Minh Ngoc: 2016-05-24 12:09:28

@polettix: I increased the time limit to 2 seconds for large test cases. Hope it is sufficient for normal Perl program.

Ha Minh Ngoc: 2016-05-24 12:04:14

@Vicky: Your solution's complexity is O(n^2) because the loop of finding minimum productive robot run too many times. You just need to optimize it.

vicky: 2016-05-23 20:14:12

how to overcome from tle?


Added by:Ha Minh Ngoc
Date:2016-05-12
Time limit:1s-2s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: GOSU