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

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

(注意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. Spring boot多模块(moudle)中的一个注入错误(Unable to start embedded container; nested exception is org)

    org.springframework.context.ApplicationContextException: Unable to start embedded container; nested ...

  2. 案例学python——案例二:连接数据库MySql

    调侃的话:案例一跑完之后,欣赏把玩了一番.人就有点飘飘然,昨天除了做饭吃饭,就是玩三国杀,江郎才尽,今天周一,不飘了,敲点代码,看看Python操作数据库有啥不一样的. 前期准备: 1.数据库 电脑上 ...

  3. CentOS 7.2:Failed to start IPv4 firewall with iptables

    问题 系统是centos7.2,且已经安装了iptables服务,但是在执行启动命令后,却报了iptables服务无法正常启动的错误. 启动命令如下: systemctl start iptables ...

  4. Vue2.0 搭配 axios

    1.安装axios $ npm install axios 2.Demo (1)Get // 为给定 ID 的 user 创建请求 axios.get('/user?ID=12345') .then( ...

  5. Centos6下zookeeper集群部署记录

    ZooKeeper是一个开放源码的分布式应用程序协调服务,它包含一个简单的原语集,分布式应用程序可以基于它实现同步服务,配置维护和命名服务等. Zookeeper设计目的 最终一致性:client不论 ...

  6. 续摄影O2O篇

    项目名:摄影O2O 工具:Eclipse ,adt,jdk1.8,MySQL 步骤:(一) 1.导入beauty项目到一个adt中,然后创建模拟器,运行(客户端) 2.导入SocketSever项目到 ...

  7. .Net反编译软件

    .Net反编译软件 https://www.cnblogs.com/xiandnc/p/10132491.html 一说起.net的反编译软件,大家首先想到的就是Reflector,ILSpy,dot ...

  8. 6-Python3从入门到实战—基础之数据类型(元组-Tuple)

    Python从入门到实战系列--目录 元组的定义 定义元组只需要在括号中添加元素,并使用逗号隔开即可 tup = ('Python','Java','C++','Kotlin') 元组与列表的区别 P ...

  9. 现代程序设计 homework-01

    搞了6个小时individual project...看看博客做一做第一次现代程序设计作业 1) 建立 GitHub 账户, 把课上做的 “最大子数组之和” 程序签入 我的github地址是https ...

  10. 转帖: 一份超全超详细的 ADB 用法大全

    增加一句 连接 网易mumu模拟器的方法 adb  connect 127.0.0.1:7555 一份超全超详细的 ADB 用法大全 2016年08月28日 10:49:41 阅读数:35890 原文 ...