我们要出租的话,一定是出租产奶量最少的牛

那我们就看出租多少头牛(其他的卖奶)的时候答案最大就可以了。

(注意N有可能小于R)

 #include<bits/stdc++.h>
#define ll long long
#define pa pair<int,int>
using namespace std;
const int maxn=; inline ll rd(){
ll x=;char c=getchar();
while(c<''||c>'') c=getchar();
while(c>=''&&c<='') x=x*+c-'',c=getchar();
return x;
} int N,M,R,C[maxn],S[maxn];
pa PQ[maxn];
ll ans,tmp,tmp2; inline bool cmp(int a,int b){return a>b;}
inline bool cmp2(pa a,pa b){return a>b;} int main(){
int i,j,k;
N=rd(),M=rd(),R=rd();
for(i=;i<=N;i++) C[i]=rd();
for(i=;i<=M;i++) PQ[i].second=rd(),PQ[i].first=rd();
for(i=;i<=R;i++) S[i]=rd();
sort(C+,C+N+,cmp);sort(PQ+,PQ+M+,cmp2);sort(S+,S+R+,cmp);
R=min(N,R);for(i=;i<=R;i++) tmp2+=S[i];
for(i=,j=;i<=N;i++){
for(;j<=M&&PQ[j].second<C[i];j++)
tmp+=1LL*PQ[j].first*PQ[j].second,C[i]-=PQ[j].second;
tmp+=1LL*PQ[j].first*C[i],PQ[j].second-=C[i];
ans=max(ans,tmp+tmp2);tmp2-=S[N-i];
}printf("%lld\n",ans);
}

luogu4181 [USACO18JAN]Rental Service (贪心)的更多相关文章

  1. 洛谷 P4181 [USACO18JAN]Rental Service

    P4181 [USACO18JAN]Rental Service 题意翻译 farmer john有N(1≤N≤100,000)头牛,他想赚跟多的钱,所以他准备买牛奶和出租牛.有M(1≤M≤100,0 ...

  2. CF2.C(二分贪心)

    C. Road to Cinema time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  3. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  4. Codeforces #380 div2 C(729C) Road to Cinema

    C. Road to Cinema time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  5. Codeforces Round #380 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 2)C. Road to Cinema 二分

    C. Road to Cinema time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  6. Road to Cinema

    Road to Cinema time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  7. Technocup 2017 - Elimination Round 2 C. Road to Cinema —— 二分

    题目链接:http://codeforces.com/problemset/problem/729/C C. Road to Cinema time limit per test 1 second m ...

  8. codeforces_738C_二分

    C. Road to Cinema time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  9. 【26.83%】【Codeforces Round #380C】Road to Cinema

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

随机推荐

  1. [Codeforces1137D]Cooperative Game

    [Codeforces1137D]Cooperative Game Tags:题解 题意 这是一道交互题. 给你一张下面这样的地图,由一条长为\(t\)的有向链和一个长为\(c\)的环构成. 现在你有 ...

  2. 你真的了解volatile关键字吗?

    volatile关键字经常在并发编程中使用,其特性是保证可见性以及有序性,但是关于volatile的使用仍然要小心,这需要明白volatile关键字的特性及实现的原理,这也是本篇文章的主要内容. 一. ...

  3. RuntimeError: Python is not installed as a framework 错误解决方案

    在virtualenv环境下使用matplotlib绘图时遇到了这样的问题: >>> import matplotlib.pyplot as pltTraceback (most r ...

  4. Linux内核分析第三章读书笔记

    第三章 进程管理 3.1 进程 进程就是处于执行期的程序 进程就是正在执行的程序代码的实时结果 线程:在进程中活动的对象.每个线程都拥有一个独立的程序计数器.进程栈和一组进程寄存器. 内核调度的对象是 ...

  5. ADC转换的分辨率

    分辨率是指ADC能够分辨量化的最小信号的能力.分辨率用二进制位数表示.例如对一个10位的ADC,其所能分辨的最小量化电平为参考电平(满量程)的2的10次方分之一.也就是说分辨率越高,就能把满量程里的电 ...

  6. shell脚本--cut命令与awk简单使用

    cut:对内容进行列切割 -d 后面的是分割符,表示用什么符号来分割符来分割列,分隔符使用引号括起来: -f后面跟着要选择的字段列,从1开始,表示第一列,如果要多列,可以用逗号分隔 : -c参数后面跟 ...

  7. Expanded encryption and decryption signature algorithm SM2 & SM3

    Expanded encryption and decryption signature algorithm supports multiple signature digest algorithms ...

  8. 转载 loadrunner的一些问题解决

    sckOutOfMemory 7 内存不足  sckInvalidPropertyValue 380 属性值不效  sckGetNotSupported 394 属性不可读  sckGetNotSup ...

  9. Win10 打开 ubuntu子系统

    1. 修改windows的设置, 增加开发人员模式 针对开人员模式 使用添加删除程序 添加 ubuntu子系统的角色 运行输入control.. 然后添加删除程序 安装完后重启 运行输入 bash 就 ...

  10. scipy优化器optimizer

    #optimazer优化器 from scipy.optimize import minimize def rosem(x): return sum(100.0*(x[1:]-x[:-1])**2.0 ...