Submit | All submissions | Best solutions | Back to list |
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.
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 |
hide comments
|
||||||
2021-07-27 06:57:10
Handling overflow is the biggest task in the problem. Enjoyed solving it. |
||||||
2020-08-13 09:15:23
Getting WA on test case1. |
||||||
2019-03-28 23:25:59
@pratjosh9: we could spend (2 x $2) on first robot to increase its productivity by 2 and spend $3 on second robot to increase its productivity by 1. Now all robots can make up to 3 products per hour and total money spend = $2 + $2 + $4= $7 |
||||||
2018-03-14 22:04:00
@mohinem: your test case gives overflow on cpp but the solution still gets AC. Last edit: 2018-03-14 22:04:15 |
||||||
2017-12-31 10:27:15
TLE in PYTHON and AC in PYPY , same code :D |
||||||
2017-12-17 06:13:36
could anyone explain the sample test case? |
||||||
2017-06-20 12:56:26
very good question....game is to find upperbound |
||||||
2017-04-24 23:40:49
The input is not sorted. |
||||||
2017-03-14 09:40:59
I do not understand the input - can we assume that Pi are sorted and there are no duplicates? |
||||||
2017-03-08 11:24:49
Just take care of overflows , by deciding the lower and upper bounds correct |