N头奶牛,价格Pi,K张优惠券,优惠券购买降为Ci,不超过M的钱最多可买多少奶牛

先将c值k小的加入,将它们省下的钱加入优先队列(省下的钱由少到多),在将k+1-n用p排序,再逐个与优先队列中弹出的比较

若省下的钱更多则赎回优惠券买这个(c+以前的p-c),否则买下全票p

不过这题的贪心其实有些奇怪,还是不太能想来

#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=j;i<=k;i++)
#define N 50010
#define inf 0x3fffffff
#define LL long long
using namespace std;
inline LL read(){
LL x=,f=;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')f=-;ch=getchar();}
while(isdigit(ch)){x=(x<<)+(x<<)+(ch^);ch=getchar();}
return x*f;}
struct nd{int p,c,k;}a[N];int n,k;LL m,sum;
priority_queue<int,vector<int>,greater<int> >q;
bool cmp1(nd a,nd b){return a.c<b.c;}
bool cmp2(nd a,nd b){return a.p<b.p;}
int main(){
// freopen("2590.in","r",stdin);
// freopen("2590.out","w",stdout);
n=read(),k=read(),m=read();
rep(i,,n)a[i].p=read(),a[i].c=read(),a[i].k=a[i].p-a[i].c;
sort(a+,a++n,cmp1);rep(i,,k){
sum+=a[i].c;if(sum>m){printf("%d",i-);return ;}
if(i==n){printf("%d",n);return ;} q.push(a[i].k);}
sort(a++k,a++n,cmp2);rep(i,k+,n){
int t=q.empty()?inf:q.top();
if(a[i].k>t){sum=sum+t+a[i].c;q.pop();
q.push(a[i].k);}else sum+=a[i].p;
if(sum>m){printf("%d",i-);return ;}
if(i==n){printf("%d",n);return ;}}
return ;
}

luogu 3045 优先队列反悔/bzoj 2590的更多相关文章

  1. luogu P2617 Dynamic Rankings && bzoj 1901 (带修改区间第k大)

    链接:https://www.luogu.org/problemnew/show/P2617 思路: 如果直接在主席树上修改的话,每次修改都会对后面所有的树造成影响,一次修改的复杂度就会变成 : n* ...

  2. Luogu 2590 [ZJOI2008]树的统计 / HYSBZ 1036 [ZJOI2008]树的统计Count (树链剖分,LCA,线段树)

    Luogu 2590 [ZJOI2008]树的统计 / HYSBZ 1036 [ZJOI2008]树的统计Count (树链剖分,LCA,线段树) Description 一棵树上有n个节点,编号分别 ...

  3. BZOJ 4823 Luogu P3756 [CQOI2017]老C的方块 (网络流、最小割)

    题目链接 (Luogu) https://www.luogu.org/problem/P3756 (BZOJ) http://lydsy.com/JudgeOnline/problem.php?id= ...

  4. BZOJ 1488 Luogu P4727 [HNOI2009]图的同构 (Burnside引理、组合计数)

    题目链接 (Luogu) https://www.luogu.org/problem/P4727 (BZOJ) https://www.lydsy.com/JudgeOnline/problem.ph ...

  5. BZOJ 4555 Luogu P4091 [HEOI2016/TJOI2016]求和 (第二类斯特林数)

    题目链接 (luogu) https://www.luogu.org/problem/P4091 (bzoj) https://www.lydsy.com/JudgeOnline/problem.ph ...

  6. BZOJ 3622 Luogu P4859 已经没有什么好害怕的了 (容斥原理、DP)

    题目链接 (Luogu) https://www.luogu.org/problem/P4859 (bzoj) https://www.lydsy.com/JudgeOnline/problem.ph ...

  7. bzoj usaco 金组水题题解(2.5)

    bzoj 2197: [Usaco2011 Mar]Tree Decoration 树形dp..f[i]表示处理完以i为根的子树的最小时间. 因为一个点上可以挂无数个,所以在点i上挂东西的单位花费就是 ...

  8. [luogu3979][bzoj3083]遥远的国度

    [luogu传送门] [bzoj传送门] 题目描述 zcwwzdjn在追杀十分sb的zhx,而zhx逃入了一个遥远的国度.当zcwwzdjn准备进入遥远的国度继续追杀时,守护神RapiD阻拦了zcww ...

  9. bzoj1644 / P1649 [USACO07OCT]障碍路线Obstacle Course

    P1649 [USACO07OCT]障碍路线Obstacle Course bfs 直接上个bfs 注意luogu的题目和bzoj有不同(bzoj保证有解,还有输入格式不同). #include< ...

随机推荐

  1. HDU46093-idiots

    题目大意 给一堆边的长度,问从中随机选出三条边来能够组成三角形的概率. 题解 其实就是要求能够组成三角形的方案数.直接从三条边入手问题会很复杂,所以我们可以先求出f[x]表示随便选出两条边长度之和为x ...

  2. Ubuntu 18.04 安装微信(Linux通用)

    Linux相关的知识:https://www.cnblogs.com/dunitian/p/4822808.html#linux 新增谷歌浏览器添加到桌面的彻底删除:https://www.cnblo ...

  3. Zabbix监控服务器硬盘状态

    安装Iptables服务: [root@localhost /]# yum install iptables-services [root@localhost /]# vim /etc/sysconf ...

  4. java ee Concurrency 并发编程

    https://www.javacodegeeks.com/2014/07/java-ee-concurrency-api-tutorial.html This is a sample chapter ...

  5. 洛谷P1896 互不侵犯

    又是一道状压DP求方案数的题... 多了一个放k个的限制,于是我们把数组多开一维. f[i][j][k]表示前i行放了j个,第i行状态为k的方案数. 然后老套路DFS转移,这次要多记录一个cnt表示上 ...

  6. pepperoni-app-kit

    ![](https://img2018.cnblogs.com/blog/1037363/201904/1037363-20190408143513171-1129511728.jpg) 哭唧唧,在g ...

  7. mysql安装和操作

    1.install: 下载地址:https://dev.mysql.com/downloads/ 2.下载zip包解压: 3.自己在该文件夹下创建 my.ini,并编辑内容: [mysql] # 设置 ...

  8. HDU3974 Assign the task

    Assign the task Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  9. 【内核】Linux内核Initrd机制解析,内核更新步骤,grub配置说明

    什么是Initrd initrd的英文含义是 boot loader initialized RAM disk,就是由boot loader初始化的内存盘.在 linux内核启动前, boot loa ...

  10. shell脚本删除log日志

    删除log文件简单shell脚本 经常会遇到日志把磁盘占满的情况,引起低级故障.我个人在实际工作中,尝试了如下的方法,比较简单,而且快捷有效. #!/bin/bash # /root/log_dele ...