QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 256 MB Total points: 100

#22482. Making Money

Statistics

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 \le N \le 100$) different cow curios, and he can buy as many of each kind of curio as his heart desires. He has only $M$ ($1 \le M \le 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 \le C_i \le 100,000$) money to purchase and yields $R_i$ ($1 \le R_i \le 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

In this case, FJ should purchase 5 curios of type 3 for 15 money and 1 more curio of type 1 for 2 money, a total of 17 money. His profit will be $5 * (7-3) + 1 * (4-2) = 5*4 + 1*2 = 22$ money. He can do no better than this given the cost and revenue structure.

NOTE: The second test case is challenging -- but our answer is correct.

Input

  • Line 1: Two space-separated integers: $N$ and $M$
  • Lines $2..N+1$: Line $i+1$ contains two space-separated integers: $C_i$ and $R_i$

Output

  • Line 1: The maximum profit FJ can generate given the costs and revenues

Examples

Input 1

3 17
2 4
5 6
3 7

Output 1

22

Problem credits: Traditional, 2009.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.