题目概述
有
n
个队伍,第
解题报告
这是一道挺简单的贪心题。
我们肯定要选气球数多于我们的队伍弄飞,且在这些队伍中选需要气球数少的队伍显然更优秀,那么我们用堆就可以快速找到最小值。
需要注意到,每次弄飞其他队伍我们的气球数也会减少,此时就会有新的气球数多于我们的队伍出现,所以弄飞一个队我们就需要重新统计一下答案,从所有答案中刷出最小的就是最小名次。
示例程序
#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long LL;
const int maxn=300000;
int n,ans;LL T,W;
pair<LL,LL> a[maxn+5];
priority_queue< LL,vector<LL>,greater<LL> > Heap;
inline bool Eoln(char ch) {return ch==10||ch==13||ch==EOF;}
inline char readc()
{
static char buf[100000],*l=buf,*r=buf;
if (l==r) r=(l=buf)+fread(buf,1,100000,stdin);
if (l==r) return EOF; else return *l++;
}
inline int readl(LL &x)
{
LL tot=0,f=1;char ch=readc(),lst='+';
while ('9'<ch||ch<'0') {if (ch==EOF) return EOF;lst=ch;ch=readc();}
if (lst=='-') f=-f;
while ('0'<=ch&&ch<='9') tot=tot*10+ch-48,ch=readc();
return x=tot*f,Eoln(ch);
}
int main()
{
freopen("program.in","r",stdin);
freopen("program.out","w",stdout);
scanf("%d",&n);n--;readl(T);readl(W);
for (int i=1;i<=n;i++) readl(a[i].first),readl(a[i].second);
sort(a+1,a+1+n);
int i=n;while (i&&a[i].first>T) Heap.push(a[i].second-a[i].first+1),i--;
ans=n-i+1;
while (!Heap.empty())
{
LL MIN=Heap.top();Heap.pop();
if (MIN>T) break;T-=MIN;n--;
while (i&&a[i].first>T) Heap.push(a[i].second-a[i].first+1),i--;
ans=min(ans,n-i+1);
}
printf("%d\n",ans);
return 0;
}