USACO18JAN Rental Service 【策略】
Description
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.
Input
The first line in the input contains , , and . The next N lines each contain an integer , indicating that Farmer John’s ith cow can produce gallons of milk every day. The next M lines each contain two integers and , indicating that the ith store is willing to buy up to qi gallons of milk for pi 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.
Output
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.
Sample Input
5 3 4
6
2
4
7
1
10 25
2 10
15 15
250
80
100
40
Sample Output
725
题意:
有n个牛,每个牛一天产加仑的奶
有m个店,可以最多卖的奶,每单位奶卖元
有r个农场,可以以一头牛元出租一天
问:一天最多赚多少钱
做法:
把每个牛产的奶从大到小排序
每个店卖的单价从大到小排序
把每个牛产的奶优先往贵的店卖,卖光后每个牛都有一个价值(产的奶卖的价格)
按牛产奶量从小到大(等价于价值从小到大),出租价格从大到小,这样比较,如果这一头牛卖奶的价值小于出租的价值,就出租(这个牛的价值赋值为租出去的价格)。
把每个牛的价值求和即为答案。
1 |
|