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

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

(注意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. 使用 cron 定时任务实现 war 自动化发布

    autoRelease.sh #!/bin/sh /home/tomcat/bin/shutdown.sh echo "tomcat stoped" cd /home/tomcat ...

  2. 【译】快速起步-JSX简介

    react version: 15.5.0 快速起步-JSX简介 思考这个变量申明: const element = <h1>Hello, world!</h1>; 这个有趣的 ...

  3. 自从硬派网倒闭后,就没有什么好看的IT硬件网站了

    RT

  4. Centos6.9下RabbitMQ集群部署记录

    之前简单介绍了CentOS下单机部署RabbltMQ环境的操作记录,下面详细说下RabbitMQ集群知识,RabbitMQ是用erlang开发的,集群非常方便,因为erlang天生就是一门分布式语言, ...

  5. poj3126 Prime Path(c语言)

    Prime Path   Description The ministers of the cabinet were quite upset by the message from the Chief ...

  6. windows上tomcat8的安装及配置

    提示:在安装tomcat之前,确定安装好jdk. 一.下载tomcat8 http://tomcat.apache.org/download-80.cgi 点击这个网址 根据自己电脑的才做系统版本安装 ...

  7. 《Linux课本》读书笔记 第四章

  8. 第三次Sprint

    Not CHECKED OUT CHECKED OUT DONE!: SPRINT GOAL: BETA-READY 修改bug 完善界面

  9. 业务-----部门Service常用逻辑

    1.org实体类 public class Org implements Serializable { private static final long serialVersionUID = 1L; ...

  10. WIN10护眼色

    参看文章:http://www.xitongcheng.com/jiaocheng/win10_article_10326.html WIN10:[HKEY_CURRENT_USER\Control ...