题意:acm队伍可以得气球,相同气球数是一个排名。每个队伍有一个气球数上限,如果该队伍的气球数大于上限

该队伍被淘汰。给了你队伍的气球数,你的气球可以给别人,问你最大可能的排名。

(2 ≤ n ≤ 300 000) (0 ≤ ti ≤ wi ≤ 10^18)

思路:对每个初始t[i]>t[1]的i,将w[i]-t[i]+1放入小根堆中

开始给气球,将给出气球后大于当前气球数的组的w[i]-t[i]+1继续放入堆中

记录给后名次的最小值即可

 const oo=;
var q,a,b,c,d:array[..]of int64; n,m,i,ans,t,w:longint;
s:int64; procedure swap(var x,y:int64);
var t:int64;
begin
t:=x; x:=y; y:=t;
end; procedure qsort(l,r:longint);
var i,j:longint;
mid1,mid2,mid3:int64;
begin
i:=l; j:=r; mid1:=a[(l+r)>>]; mid2:=b[(l+r)>>]; mid3:=c[(l+r)>>];
repeat
while (mid1<a[i])or(mid1=a[i])and(mid2>b[i])or
(mid1=a[i])and(mid2=b[i])and(mid3>c[i]) do inc(i);
while (mid1>a[j])or(mid1=a[j])and(mid2<b[j])or
(mid1=a[j])and(mid2=b[j])and(mid3<c[j]) do dec(j);
if i<=j then
begin
swap(a[i],a[j]); swap(b[i],b[j]); swap(c[i],c[j]);
inc(i); dec(j);
end;
until i>j;
if l<j then qsort(l,j);
if i<r then qsort(i,r);
end; function min(x,y:longint):longint;
begin
if x<y then exit(x);
exit(y);
end; procedure shiftup(x,m:longint);
begin
while (x>)and(q[x]<q[x>>]) do
begin
swap(q[x],q[x>>]);
x:=x>>;
end;
end; procedure shiftdown(x,m:longint);
var t:longint;
begin
while (x<<)<=m do
begin
t:=x<<;
if (t+<=m)and(q[t]>q[t+]) then t:=t+;
if q[x]>q[t] then
begin
swap(q[x],q[t]);
x:=t;
end
else break;
end;
end; begin
//assign(input,'cf725D.in'); reset(input);
//assign(output,'cf725D.out'); rewrite(output);
readln(n);
for i:= to n do
begin
read(a[i],b[i]);
c[i]:=i;
end;
qsort(,n);
for i:= to n do d[c[i]]:=i;
for i:= to d[]- do
begin
inc(m); q[m]:=b[i]-a[i]+; shiftup(m,m);
end;
s:=a[d[]];
for i:= to d[] do
if a[i]>a[d[]] then inc(ans);
inc(ans); t:=ans;
w:=d[]+;
while m> do
begin
if s-q[]>= then
begin
s:=s-q[]; q[]:=oo; shiftdown(,m); dec(t);
while (w<=n)and(a[w]>s) do
begin
inc(m); q[m]:=b[w]-a[w]+; shiftup(m,m);
inc(w); inc(t);
end;
ans:=min(ans,t);
end
else break;
end;
writeln(ans);
//close(input);
//close(output);
end.
05-11 20:30