[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 N N cows (1N100,000), each capable of producing some amount of milk every day. The M M stores near FJ’s farm (1M100,000) each offer to buy a certain amount of milk at a certain price. Moreover, Farmer John’s R(1R100,000) R ( 1 ≤ R ≤ 100 , 000 ) 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 N N , M, and R R . The next N lines each contain an integer ci(1ci1,000,000), indicating that Farmer John’s ith cow can produce ci c i gallons of milk every day. The next M lines each contain two integers qi q i and pi(1qi,pi1,000,000) p i ( 1 ≤ q i , p i ≤ 1 , 000 , 000 ) , 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 qi q i gallons to a given store. The next R R lines each contain an integer ri(1ri1,000,000), indicating that one of Farmer John’s neighbors wants to rent a cow for ri r i 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个牛,每个牛一天产 ci c i 加仑的奶
有m个店,可以最多卖 qi q i 的奶,每单位奶卖 pi p i
有r个农场,可以以一头牛 ri r i 元出租一天
问:一天最多赚多少钱


做法:
把每个牛产的奶从大到小排序
每个店卖的单价从大到小排序
把每个牛产的奶优先往贵的店卖,卖光后每个牛都有一个价值(产的奶卖的价格)
按牛产奶量从小到大(等价于价值从小到大),出租价格从大到小,这样比较,如果这一头牛卖奶的价值小于出租的价值,就出租(这个牛的价值赋值为租出去的价格)。
把每个牛的价值求和即为答案。

#include<iostream>
#include<stdio.h>
#include<string>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
const int MAXN = 100000 + 5;
ll n, m, r;
ll niu[MAXN];
struct dd
{
    ll up;
    ll p;
    bool operator<(const dd xd)const {
        if (p == xd.p)
            return up > xd.up;
        return p > xd.p;
    }
}d[MAXN];
ll zu[MAXN];
ll jia[MAXN];
bool cmp(ll a, ll b)
{
    return a > b;
}
int main()
{
    scanf("%lld%lld%lld", &n, &m, &r);
    for (int i = 0; i < n; i++)
    {
        scanf("%lld", &niu[i]);
    }
    for (int i = 0; i < m; i++)
    {
        scanf("%lld%lld", &d[i].up, &d[i].p);
    }
    for (int i = 0; i < r; i++)
    {
        scanf("%lld", &zu[i]);
    }
    sort(d, d + m);
    sort(niu, niu + n,cmp);
    sort(zu, zu + r, cmp);
    int k = 0;
    for (int i = 0; i < n; i++)
    {
        if (k >= m)
        {
            break;
        }
        while (niu[i]>0)
        {
            if (k >= m)
            {
                break;
            }
            if (niu[i] >= d[k].up)
            {
                niu[i] -= d[k].up;
                jia[i] += d[k].up*d[k].p;
                d[k].up = 0;
                k++;
            }
            else
            {
                jia[i] += niu[i] * d[k].p;
                d[k].up -= niu[i];
                niu[i] = 0;
            }
        }
    }
    k = 0;
    for (int i = n - 1; i >= 0; i--)
    {
        if (k >= r)
            break;
        if (jia[i] < zu[k])
        {
            jia[i] = zu[k];
            k++;
        }
    }
    ll ans = 0;
    for (int i = 0; i < n; i++)
    {
        ans += jia[i];
    }
    printf("%lld\n", ans);
}
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值