Contest Balloons

时间:2023-03-09 10:02:17
Contest Balloons

Contest Balloons

题目链接:http://codeforces.com/problemset/problem/725/D

贪心+枚举

每次在排名在自己前面的选出w-t值最小的送气球,更新rank即可。

(一直觉得cin比scanf不会慢太多,结果我跑出来是2000ms,队友300ms...)

代码如下:

 #include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#define Min(x,y) (x<y?x:y)
#define N 300005
using namespace std;
typedef long long LL;
LL n,k,t,w,rk,ans,index;
struct nod{
LL t,w,diff;
nod(LL tt=,LL ww=){
t=tt,w=ww;
diff=w-t;
}
bool operator < (const nod &b)const{
return diff>b.diff;
}
}a[N];
bool cmp(nod a,nod b){
return a.t>b.t;
}
priority_queue<nod>pq;
int main(void){
scanf("%I64d",&n);
scanf("%I64d%I64d",&t,&w);
for(LL i=;i<n;++i){
LL t,w;
scanf("%I64d%I64d",&t,&w);
if(t<=w)a[k++]=nod(t,w);
}
sort(a,a+k,cmp);
for(;index<k;++index){
if(a[index].t<=t)break;
pq.push(a[index]);
}
rk=ans=index+;
while(!pq.empty()){
nod temp=pq.top();
pq.pop();
t-=temp.diff+;
if(t<)break;
LL i=;
for(;i+index<k;++i){
if(a[i+index].t<=t)break;
pq.push(a[i+index]);
}
rk+=i-;
index+=i;
ans=Min(ans,rk);
}
printf("%I64d\n",ans);
}