比赛 20160415 评测结果 AAAAAAAAAA
题目名称 烤鸡翅 最终得分 100
用户昵称 5007 运行时间 0.366 s
代码语言 Pascal 内存使用 2.07 MiB
提交时间 2016-04-17 15:56:02
显示代码纯文本
var
n,i,y,max,d,ren,r:longint;tot:int64;
x,que:array [0..250010]of longint;
procedure swap(x,y:longint);var i:longint;begin
i:=que[x]; que[x]:=que[y]; que[y]:=i;
end;
procedure insert(y,x:longint);begin
  que[x]:=y;
  while (x>1)and(que[x]>que[x div 2]) do
    begin
       swap(x,x div 2);
       x:=x div 2;
    end;
end;
procedure down;var i,j:longint;begin
  i:=1;
  if i*2+1<=r then
	 begin
	 if que[i*2]>que[i*2+1] then j:=i*2 else j:=i*2+1;
	 end
	 else if i*2<=r then j:=i*2 else exit;
  while que[i]<que[j] do
    begin
      swap(i,j);
      i:=j;
      if i *2+1<=r then
        begin
          if que[i*2]>que[i*2+1] then j:=i*2 else j:=i * 2+1;
        end
      else if i *2<=r then j:=i *2 else exit;
    end;
end;
begin
assign(input,'wing.in');reset(input);
assign(output,'wing.out');rewrite(output);
  read(n);
  tot:=0;  r:=0;
  for i:=1 to n do read(x[i]);
  for i:=1 to n do
    begin
      inc(tot,x[i]);
      read(y);
      if  tot>=y then
        begin
          inc(r);
          insert(y,r);
          dec(tot,y);
          inc(ren);
		  //writeln('have ',y,' ',tot,' ',ren);
        end else
      begin
        if que[1]>y then 
		 begin 
		 //writeln(que[1],' ',y);
		 inc(tot,que[1]-y); que[1]:=y; down; 
		 //writeln('have ',y,' ',tot,' ',ren,' ',que[1]);
		 end;
      end;
    end;
write(ren);
close(input);close(output);
end.