Canada Cup 2016 D. Contest Balloons
最近好弱做什么题目都是做一晚上
这是合肥站炼铜后遗症?
这题就是贪心
我已开始还写了1小时………三分…………….
#include<bits/stdc++.h>
using namespace std;
#define sz(X) ((int)X.size())
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int N = 3e5+5;
struct Node{
int id; ll t, w;
}p[N];
bool cmp1(Node a,Node b) {
if(a.t != b.t) return a.t < b.t;
else return a.id > b.id;
}
int main(){
int n;
while(~scanf("%d",&n)) {
priority_queue<ll,vector<ll>,greater<ll>> Q;
for(int i = 1; i <= n; ++i) {
scanf("%lld %lld",&p[i].t,&p[i].w); p[i].id = i;
}
int ans = INF;
int tmp = 1;
sort(p+1, p+n+1,cmp1);
int fl = 0;
ll ret = 0; ll pre;
for(int i = n; i >= 1; --i) {
if(fl) {
ret += pre - p[i].t;
if(pre == p[i].t) {
tmp ++; Q.push(p[i].w - p[i].t + 1);
continue;
}
pre = p[i].t;
while(!Q.empty()) {
ll x = Q.top();
if(x > ret) break;
Q.pop(); ret -= x; tmp --;
}
ans = min(ans, tmp);
tmp ++; Q.push(p[i].w-p[i].t+1);
}else {
if(p[i].id == 1) {
fl = 1; ans = min(ans, tmp);
pre = p[i].t;
}else {
Q.push(p[i].w-p[i].t+1);
// if(n == 7) printf("%lld %d\n",p[i].t,tmp);
tmp ++;
}
}
}
ret += pre;
while(!Q.empty()) {
ll x = Q.top();
if(x > ret) break;
Q.pop(); ret -= x; tmp --;
}
ans = min(ans, tmp);
printf("%d\n", ans);
}
return 0;
}
Canada Cup 2016 D. Contest Balloons的更多相关文章
- Canada Cup 2016 D. Contest Balloons 好题。优先队列 + 简单贪心
http://codeforces.com/contest/725/problem/D 这题一看就是贪心的了,w - t最小的那个,肯定是优先打死. 但是一直都不会写,为什么呢,因为这个太像二分答案了 ...
- 【Codeforces Round 725】Canada Cup 2016
模拟Canada Cup 2016,ABC三题,Rank1376 第三题卡住了 Codeforces 725 C 求出两个相同字符的位置,记为x和y. 然后考虑把相同的那个字符放在第一行的什么地方, ...
- Canada Cup 2016 C. Hidden Word 构造模拟题
http://codeforces.com/contest/725/problem/C Each English letter occurs at least once in s. 注意到题目有这样一 ...
- Codeforces Canada Cup 2016
A. Jumping Ball time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- Canada Cup 2016 C. Hidden Word
C. Hidden Word time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
- CodeForces Canada Cup 2016【A,B,C,D】
CodeForces 725A: 思路就是如果"最左"不是'>'这个了,那么这个右边的一定不可能到达左边了: 同理最右: CodeForces 725B: 有两个空姐,一个从 ...
- codeforces 725D . Contest Balloons(贪心+优先队列)
题目链接:codeforces 725D . Contest Balloons 先按气球数从大到小排序求出初始名次,并把名次排在第一队前面的队放入优先队列,按w-t-1值从小到大优先,然后依次给气球给 ...
- Contest Balloons
Contest Balloons 题目链接:http://codeforces.com/problemset/problem/725/D 贪心+枚举 每次在排名在自己前面的选出w-t值最小的送气球,更 ...
- CodeForces - 725D Contest Balloons 贪心
D. Contest Balloons time limit per test 3 seconds memory limit per test 2 ...
随机推荐
- Hadoop学习笔记四
一.fsimage,edits和datanode的block在本地文件系统中位置的配置 fsimage:hdfs-site.xml中的dfs.namenode.name.dir 值例如file:// ...
- CF 455D. Serega and Fun [分块 deque]
Serega and Fun 题意: [l,r]循环右移一位,查询区间内某个数出现次数 为什么好多人用链表?反正我是不会写双向链表 完全可以分块然后模拟啊...中间的块只会插入删除一个元素呀....用 ...
- BZOJ 1069: [SCOI2007]最大土地面积 [旋转卡壳]
1069: [SCOI2007]最大土地面积 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 2978 Solved: 1173[Submit][Sta ...
- [Python Study Notes]CS架构远程访问获取信息--Client端
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ...
- 升级gitlab
https://gitlab.com/gitlab-org/gitlab-ce/tree/master/doc/update https://about.gitlab.com/update/#cent ...
- css去除ios文本框默认圆角
css去除ios文本框默认圆角 input, textarea {-webkit-appearance: none;}
- CUP、内存、磁盘是如何在一起工作的
IT技术发展到今天,计算机能做的事情可谓复杂的多.那么计算机是如何做出如此复杂的运算的呢? 不准确的说,计算机主要做两件事,数据计算和数据存储. 第一先说说计算机是如何计算的吧. 我们平时见到的所有计 ...
- C#实现七牛云存储
云存储,就是把本地的资源文件存放至网络上,可以公网访问.相当于网盘功能,感觉非常方便. 这里介绍的是七牛云存储.有兴趣的可以去官方网站详看 根据官网的介绍,本身是提供SDK的,下载地址,大家可以根据自 ...
- 轻松搭建Git服务器(Ubuntu)
搭建Git服务器 在远程仓库节中,我们讲了远程仓库实际上和本地仓库没啥不同,纯粹为了7x24小时开机并交换大家的修改. GitHub就是一个免费托管开源代码的远程仓库.但是对于某些视源代码如生命的商业 ...
- hdu 2047递推
A[N]表示以E或者F结尾的情况下的方案数,B[N]表示以O结尾的情况下的方案数,F[N]=3*A[N-1]+2*B[N-1] 同时,A[N]=2*B[N-1]+2*A[N-1],B[N-1]=A[N ...