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

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

(注意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. [Spark][Hive]外部文件导入到Hive的例子

    外部文件导入到Hive的例子: [training@localhost ~]$ cd ~[training@localhost ~]$ pwd/home/training[training@local ...

  2. maven项目中 org.hibernate.MappingNotFoundException: resource:*.hbm.xml not found问题的解决方案

    是因为*.hbm.xml没有放到resource的mapper下导致的 对于Maven工程,编译的工作是由Maven程序来完成的,而Maven默认只会把src/main/resources文件夹下的文 ...

  3. Notepad++中的颜色属性设置大全

    Indent guideline style  缩进参考线的颜色Brace highlight style 鼠标指针在框架左右时框架的颜色(如css中{}   js中的())Bad brace col ...

  4. [UWP 自定义控件]了解模板化控件(5.1):TemplatePart vs. VisualState

    1. TemplatePart vs. VisualState 在前面两篇文章中分别使用了TemplatePart及VisualState的方式实现了相同的功能,其中明显VisualState的方式更 ...

  5. MySQL主主同步配置

    1. MySQL主主配置过程 在上一篇实现了主从同步的基础上,进行主主同步的配置. 这里用node19(主),node20(从)做修改,使得node19和node20变为主主同步配置模式 修改配置文件 ...

  6. Microsoft Office软件自定义安装目录

    Microsoft Office安装时不能手动设置安装目录,本文描述通过修改注册表的方式自定义安装目录 1.同时按下快捷键 win + r 启动运行 2.输入 regedit 打开注册表 3.找到   ...

  7. bootstrap是什么

    Bootstrap,来自 Twitter,是目前最受欢迎的前端框架. Bootstrap 是基于 HTML.CSS.JAVASCRIPT 的,它简洁灵活,使得 Web 开发更加快捷. 本教程将向您讲解 ...

  8. 多校寒训TaoTao要吃鸡dp

    题目描述 Taotao的电脑带不动绝地求生,所以taotao只能去玩pc版的荒野行动了, 和绝地求生一样,游戏人物本身可以携带一定重量m的物品,装备背包 之后可以多携带h(h为0代表没有装备背包)重量 ...

  9. 剑指offer:复杂链表的复制

    题目描述: 输入一个复杂链表(每个节点中有节点值,以及两个指针,一个指向下一个节点,另一个特殊指针指向任意一个节点),返回结果为复制后复杂链表的head.(注意,输出结果中请不要返回参数中的节点引用, ...

  10. 使用Java+Kotlin双语言的LeetCode刷题之路(一)

    LeetCode learning records based on Java,Kotlin,Python...Github 地址 序号对应 LeetCode 中题目序号 1 两数之和 给定一个整数数 ...