洛谷 P4181 [USACO18JAN]Rental Service
题意翻译
farmer john有N(1≤N≤100,000)头牛,他想赚跟多的钱,所以他准备买牛奶和出租牛。有M(1≤M≤100,000 )家商店想买牛奶,每家商店的进货价不同。有R(1≤R≤100,000 )户邻居想租牛,每户人家的租价不同。 问他最多能赚多少钱。
输入:输入的第1行包含n,m,r三个整数。紧接着的n行每一行有1个整数Ci (1≤Ci≤1,000,000),表示第i头牛产出Ci加仑奶。再下面的m行每行有两个整数Qi与Pi (1≤Qi,Pi≤1,000,000),表示第i个商店最多以Pi美分每加仑的价格购买Qi加仑牛奶。FJ可销售0~Qi加仑牛奶到一个商店。然后的r行每行有一个整数Ri,表示FJ的第i个邻居想以Ri(1≤Ri≤1,000,000 ), 的价格租一头牛。
输出:仅一行。表示一天最多获得多少钱。
注意:int类型不够大!!!
说明: FJ 需要挤一号和四号奶牛的奶,共可得牛奶13加仑。他可以先买给出价最高的10加仑,赚250美分,然后把剩下的按每加仑15美分去卖,共有295美分的利润。 然后,他要把其他三头以250,80,和100美分的价格分别卖出,赚430美分。所以他一共可得725美分/日的利润。
---by 风格雨关、WuYongxuan、毕沁露
题目描述
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 NN cows (1 \leq N \leq 100,0001≤N≤100,000), each capable of producing some amount of milk every day. The MMstores near FJ's farm (1 \leq M \leq 100,0001≤M≤100,000) each offer to buy a certain amount of milk at a certain price. Moreover, Farmer John's RR (1 \leq R \leq 100,0001≤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.
输入输出格式
输入格式:
The first line in the input contains NN, MM, and RR. The next NN lines each contain an integer c_ici (1 \leq c_i \leq 1,000,0001≤ci≤1,000,000), indicating that Farmer John's iith cow can produce c_ici gallons of milk every day. The next MMlines each contain two integers q_iqi and p_ipi (1 \leq q_i, p_i \leq 1,000,0001≤qi,pi≤1,000,000), indicating that the iith store is willing to buy up to q_iqi gallons of milk for p_ipi cents per gallon. Keep in mind that Farmer John can sell any amount of milk between zero and q_iqi gallons to a given store. The next RR lines each contain an integer r_iri (1 \leq r_i \leq 1,000,0001≤ri≤1,000,000), indicating that one of Farmer John's neighbors wants to rent a cow for r_iri cents per day.
输出格式:
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. Note that the output might be too large to fit into a standard 32-bit integer, so you may need to use a larger integer type like a "long long" in C/C++.
输入输出样例
说明
Farmer John should milk cows #1 and #4, to produce 13 gallons of milk. He should completely fill the order for 10 gallons, earning 250 cents, and sell the remaining three gallons at 15 cents each, for a total of 295 cents of milk profits.
Then, he should rent out the other three cows for 250, 80, and 100 cents, to earn 430 more cents. (He should leave the request for a 40-cent rental unfilled.) This is a total of 725 cents of daily profit.
#include<queue>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef pair<int, int>P;
typedef long long ll;
const int MAXN=1e5+;
P shop;
int N,M,R;
int buy[MAXN],cow[MAXN];
priority_queue<P> q;
int main(){
cin>>N>>M>>R;
for(int i=;i<=N;i++) scanf("%d",&cow[i]);
for(int i=;i<=M;i++){
scanf("%d%d",&shop.second,&shop.first);
q.push(shop);
}
for(int i=;i<=R;i++)scanf("%d",&buy[i]);
sort(cow+,cow+N+);
sort(buy+,buy+R+);
int l=,r=N,b=R;
ll ans=,tmp=-;
for(int i=;i<=N;i++){
if(tmp==-)
while(!q.empty()&&cow[r]){
if(tmp==-) tmp=;
if(q.top().second>cow[r]) {
P p=q.top();q.pop();
tmp+=1LL*cow[r]*p.first,
p.second-=cow[r],cow[r]=;
q.push(p);
}
else
tmp+= 1LL*q.top().first*q.top().second,
cow[r]-=q.top().second, q.pop();
}
if(tmp!=-&&tmp>=buy[b])
ans+=tmp,tmp=-,--r;
else if(b!=) ans+=buy[b--],++l;
}
cout<<ans<<endl;
return ;
}
洛谷 P4181 [USACO18JAN]Rental Service的更多相关文章
- [洛谷P4183][USACO18JAN]Cow at Large P
题目链接 Bzoj崩了之后在洛谷偶然找到的点分好题! 在暴力的角度来说,如果我们$O(n)$枚举根节点,有没有办法在$O(n)$的时间内找到答案呢? 此时如果用树形$dp$的想法,发现是可做的,因为可 ...
- 洛谷 P4183 - [USACO18JAN]Cow at Large P(点分治)
洛谷题面传送门 点分治 hot tea. 首先考虑什么样的点能够对以 \(u\) 为根的答案产生 \(1\) 的贡献.我们考虑以 \(u\) 为根对整棵树进行一遍 DFS.那么对于一个点 \(v\), ...
- luogu4181 [USACO18JAN]Rental Service (贪心)
我们要出租的话,一定是出租产奶量最少的牛 那我们就看出租多少头牛(其他的卖奶)的时候答案最大就可以了. (注意N有可能小于R) #include<bits/stdc++.h> #defin ...
- 2018.10.25 洛谷P4187 [USACO18JAN]Stamp Painting(计数dp)
传送门 其实本来想做组合数学的2333. 谁知道是道dpdpdp. 唉只能顺手做了 还是用真难则反的思想. 这题我们倒着考虑,只需要求出不合法方案数就行了. 这个显然是随便dpdpdp的. f[i]f ...
- [洛谷P4185] [USACO18JAN]MooTube
题目链接: 传送门 题意: 给定一颗N个节点的树,定义两点距离为他们之间路径中边权最小值. Q次询问K,V,询问到V距离>=K的点有多少(不含V) 呃呃呃呃考试的时候直奔了T3,结果公式推挂了( ...
- 洛谷AT2342 Train Service Planning(思维,动态规划,珂朵莉树)
洛谷题目传送门 神仙思维题还是要写点东西才好. 建立数学模型 这种很抽象的东西没有式子描述一下显然是下不了手的. 因为任何位置都以\(k\)为周期,所以我们只用关心一个周期,也就是以下数都在膜\(k\ ...
- 洛谷 1938 [USACO09NOV]找工就业Job Hunt
洛谷 1938 [USACO09NOV]找工就业Job Hunt 题目描述 Bessie is running out of money and is searching for jobs. Far ...
- 洛谷1640 bzoj1854游戏 匈牙利就是又短又快
bzoj炸了,靠离线版题目做了两道(过过样例什么的还是轻松的)但是交不了,正巧洛谷有个"大牛分站",就转回洛谷做题了 水题先行,一道傻逼匈牙利 其实本来的思路是搜索然后发现写出来类 ...
- 洛谷P1352 codevs1380 没有上司的舞会——S.B.S.
没有上司的舞会 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题目描述 Description Ural大学有N个职员,编号为1~N.他们有 ...
随机推荐
- [BZOJ2809][Apio2012]dispatching 贪心+可并堆
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2809 我们考虑以每一个节点作为管理者所得的最优答案,一定是优先选择所要薪水少的忍者.那么首 ...
- 从0开始搭建SQL Server 2012 AlwaysOn 第三篇(安装数据,配置AlwaysOn)
这一篇是从0开始搭建SQL Server 2012 AlwaysOn 的第三篇,这一篇才真正开始搭建AlwaysOn,前两篇是为搭建AlwaysOn 做准备的 操作步骤: 1.安装SQL server ...
- 关于mapState和mapMutations和mapGetters 和mapActions辅助函数的用法及作用(二)-----mapMutations
在组件中提交Mutations: import { mapState, mapMutations } from 'vuex' export default { data() { return { ms ...
- C++模版完全解析
模版 模版在C++中是一个很重要的概练,生活中的模版也是随处可见,比如制造工程师会 哪一个模子去构造出一个一个的工件,C++程序员能够用模版去实例化y有相同操作 不同类型的函数或者数据结构.简单的理解 ...
- zookeeper、consul 实现注册中心
1.Zookeeper 分布式协调工具,可以实现注册中心 所有实现方式基本一致,只需要先开启zookeeper的服务端,然后再打开客户端jar包即可. Zookeeper一开始连接失败,后面又可以了, ...
- chvt - 修改虚拟终端的前台环境
SYNOPSIS(总览) chvtN DESCRIPTION(描述) chvt N 命令用来生成 /dev/ttyN 的前台终端.如果它本来不存在,即创建相应的屏幕.为了删除掉不用的VT(虚拟终端), ...
- CAD参数绘制多行文字(网页版)
在CAD设计时,需要绘制多行文字,用户可以设置设置绘制文字的高度等属性. 主要用到函数说明: _DMxDrawX::DrawMText 绘制一个多行文字.详细说明如下: 参数 说明 DOUBLE dP ...
- Spring对象类型——单例和多例
由于看淘淘商城的项目,涉及到了项目中处理spring中bean对象的两种类型,分别是单例和多例,就在此记录一下,方便加深理解,写出更加健壮的代码. 一.单例和多例的概述 在Spring中,bean可以 ...
- ORACLE IN 与NOT IN 的性能区别
业务问题大概可以这样描述,一个父表,一个子表,查询的结果是找到子表中没有使用父表id的记录,这种情况估计很多系统都会牵涉得到.让我们来举一个例子: 表一: 父表 parent 表二: 子表 child ...
- react-native 框架升级 安卓第三方插件报错 Android resource linking failed
亲自经历react-native从0.55升级到0.58的过程,有点坎坷,ios出现的问题还算不多,但是android这里,随着gradle和buildTool的使用升级,导致第三方插件出现各种问题, ...