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≤P≤109) and Mi (1≤Mi≤109) – information of the robot i-th

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

hide comments
chawlaroxx_06: 2017-12-31 10:27:15

TLE in PYTHON and AC in PYPY , same code :D

pratjosh9: 2017-12-17 06:13:36

could anyone explain the sample test case?

viratian_070: 2017-06-20 12:56:26

very good question....game is to find upperbound

bnzhaxx: 2017-04-24 23:40:49

The input is not sorted.

kasiekdec: 2017-03-14 09:40:59

I do not understand the input - can we assume that Pi are sorted and there are no duplicates?

aman224: 2017-03-08 11:24:49

Just take care of overflows , by deciding the lower and upper bounds correct

kapillamba4: 2017-01-31 12:22:01

0.14 seconds using map

Last edit: 2017-09-28 13:02:50
vengatesh15: 2017-01-24 18:35:30

Take care about the upper bound that cost me 1 WA...

in_arena: 2017-01-03 09:49:51

good one !! 50th

Chinmay Kousik: 2016-11-26 13:37:08

My code is getting the correct answer on randomly generated test cases but WA here. Please help. submission id: 18262733


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