FJ has gone into the curio business, buying and selling knickknacks
like cow Christmas tree ornaments. He knows he will sell every
single curio he can stock from a catalog of N (1 <= N <= 100)
different cow curios, and he can buy as many of each kind of curio
as his heart desires. He has only M (1 <= M <= 100,000) money to
invest but wants to maximize his profit (which has a slightly unusual
definition) at the end of his first year in business.
Curio type i costs C_i (1 <= C_i <= 100,000) money to purchase and
yields R_i (1 <= R_i <= 100,000) revenue for each curio sold (a profit of R_i-C_i). FJ can mix and match the curios he sells in any
way he wishes. He need not spend all his money when purchasing
curios.
What is the greatest amount of total profit (profit = initial_cash
- all_costs + all_sales) FJ can have at the end of his first year?
This number is guaranteed to be less than 1,000,000,000.
Consider the situation when FJ has just 3 kinds of curios and starts
with M=17. Below are the cost and revenue numbers for each curio:
Curio Cost Revenue
# C_i R_i
1 2 4
2 5 6
3 3 7
NOTE: The second test case is challenging -- but our answer is correct.
There are multiple test cases in the input file.
3 17 2 4 5 6 3 7 3 17 2 4 5 6 3 7
22 22
Migrated from old NTUJ.
USACO QUAL10
No. | Testdata Range | Score |
---|