#P1208. [USACO1.3] Mixing Milk
[USACO1.3] Mixing Milk
题目描述
The Merry Milk Makers company buys milk from farmers, packages it into attractive 1- and 2-Unit bottles, and then sells that milk to grocery stores so we can each start our day with delicious cereal and milk.
Since milk packaging is such a difficult business in which to make money, it is important to keep the costs as low as possible. Help Merry Milk Makers purchase the farmers' milk in the cheapest possible manner. The MMM company has an extraordinarily talented marketing department and knows precisely how much milk they need each day to package for their customers.
The company has contracts with several farmers from whom they may purchase milk, and each farmer has a different price at which they sell milk to the packing plant. A herd of cows can only produce so much milk each day, so the farmers already know how much milk they will have available.
Each day, Merry Milk Makers can purchase an integer number of units of milk from each farmer, a number that is always less than or equal to the farmer's limit. This might be the entire production from that farmer, none of the production, or any integer in between.
Given:
- the Merry Milk Makers' daily requirement of milk,
- the cost per unit for milk from each farmer,
- the amount of milk available from each farmer,
Calculate the minimum amount of money that Merry Milk Makers must spend to meet their daily need for milk.
Note: The total milk produced per day by the farmers will always be sufficient to meet the demands of the Merry Milk Makers even if the prices are high.
输入格式
- Line 1: Two integers, and .
The first value, () is the amount of milk that Merry Milk Makers wants per day.
The second, () is the number of farmers that they may buy from.
- Lines 2 through : The next lines each contain two integers: and .
() is price in cents that farmer charges.
() is the amount of milk that farmer can sell to Merry Milk Makers per day.
输出格式
A single line with a single integer that is the minimum cost that Merry Milk Makers must pay for one day's milk.
100 5
5 20
9 40
3 10
8 80
6 30
630
提示
Input Explanation
100 5 means MMM wants units of milk from farmers.
5 20 means farmer 1 says, "I can sell you units at cents per unit".
9 40 and 3 10 are similar.
8 80 means farmer 4 says, "I can sell you units at cents per unit".
6 30 means farmer 5 says, "I can sell you units at cents per unit".
Output Explanation
Here is how the MMM company spent only cents to purchase units of milk:
| Price per unit | Units available | Units bought | Price units | Total cost | Notes |
|---|---|---|---|---|---|
| Bought no milk from farmer | |||||
| Did not buy all units | |||||
| Total | Cheapest total cost | ||||
USACO Training Section 1.3.