luogu#P4181. [USACO18JAN] Rental Service S
[USACO18JAN] Rental Service S
题目描述
Farmer John realizes that the income he receives from milk production is insufficient to fund the growth of his farm, so to earn some extra money, he launches a cow-rental service, which he calls "USACOW" (pronounced "Use-a-cow").
Farmer John has cows (), each capable of producing some amount of milk every day. The stores near FJ's farm () each offer to buy a certain amount of milk at a certain price. Moreover, Farmer John's () neighboring farmers are each interested in renting a cow at a certain price.
Farmer John has to choose whether each cow should be milked or rented to a nearby farmer. Help him find the maximum amount of money he can make per day.
输入格式
The first line in the input contains , , and . The next lines each contain an integer (), indicating that Farmer John's th cow can produce gallons of milk every day. The next lines each contain two integers and (), indicating that the th store is willing to buy up to gallons of milk for cents per gallon. Keep in mind that Farmer John can sell any amount of milk between zero and gallons to a given store. The next lines each contain an integer (), indicating that one of Farmer John's neighbors wants to rent a cow for cents per day.
输出格式
The output should consist of one line containing the maximum profit Farmer John can make per day by milking or renting out each of his cows. Note that the output might be too large to fit into a standard 32-bit integer, so you may need to use a larger integer type like a "long long" in C/C++.
题目大意
Farmer John 有 () 头牛,他想赚更多的钱,所以他准备买牛奶和出租牛。有 () 家商店想买牛奶,每家商店的进货价不同。有 () 户邻居想租牛,每户人家的租价不同。 问他最多能赚多少钱。
输入:输入的第 行包含 ,, 三个整数。紧接着的 行每一行有1个整数 (),表示第 头牛产出 加仑奶。再下面的 行每行有两个整数 与 (),表示第 个商店最多以 美分每加仑的价格购买 加仑牛奶。Farmer John 可销售 加仑牛奶到一个商店。接下来的 行每行有一个整数 ,表示 Farmer John 的第 个邻居想以 () 的价格租一头牛。
输出:仅一行。表示一天最多获得多少钱。
注意:int 类型不够大!!!
说明:Farmer John 需要挤一号和四号奶牛的奶,共可得牛奶 加仑。他可以先买给出价最高的 加仑,赚 美分,然后把剩下的按每加仑 美分去卖,共有 美分的利润。 然后,他要把其他三头以 , 和 美分的价格分别卖出,赚 美分。所以他一共可得 美分/日的利润。
---by 风格雨关、WuYongxuan、毕沁露
5 3 4
6
2
4
7
1
10 25
2 10
15 15
250
80
100
40
725
提示
Farmer John should milk cows #1 and #4, to produce 13 gallons of milk. He should completely fill the order for 10 gallons, earning 250 cents, and sell the remaining three gallons at 15 cents each, for a total of 295 cents of milk profits.
Then, he should rent out the other three cows for 250, 80, and 100 cents, to earn 430 more cents. (He should leave the request for a 40-cent rental unfilled.) This is a total of 725 cents of daily profit.