比赛 20121023 评测结果 AAWAAAWATT
题目名称 奶牛晒衣服 最终得分 60
用户昵称 FrCsKOH 运行时间 2.871 s
代码语言 Pascal 内存使用 3.98 MiB
提交时间 2012-10-23 21:16:38
显示代码纯文本
program C1210;
 const Be=500000;
 var qA,qB:array[1..Be] of longint;
     n,A,B,i,Ha,Ea,Hb,Eb,temp,t:longint;
 procedure down(i,m:longint);
  begin
   while i<<1<=m do begin
    i:=i<<1;
    if (i<m) and (qA[i]>qA[i+1]) then inc(i);
    if qA[i]<qA[i>>1] then begin
     temp:=qA[i];
     qA[i]:=qA[i>>1];
     qA[i>>1]:=temp;
    end else break;
   end;
  end;

 procedure HeapSort;
  var i:longint;
  begin
   for i:=n>>1 downto 1 do down(i,n);
   for i:=n downto 2 do begin
    temp:=qA[i];
    qA[i]:=qA[1];
    qA[1]:=temp;
    down(1,i-1);
   end;
  end;

 begin
  assign(input,'dry.in');
  reset(input);
  assign(output,'dry.out');
  rewrite(output);

  readln(n,A,B);
  for i:=1 to n do read(qA[i]);
  readln;

  HeapSort;

  fillchar(qB,sizeof(qB),0);
  Ha:=1;
  Ea:=n;
  Hb:=1;
  Eb:=0;
  t:=0;

  while not((Ha>Ea) and (Hb>Eb)) do begin
   inc(t);
   for i:=Ha to Ea do dec(qA[i],A);
   for i:=Hb to Eb do dec(qB[i],A);
   dec(qA[Ha],B);

   while (Ha<=Ea) and (qA[Ea]<=0) do dec(Ea);
   while (Hb<=Eb) and (qB[Eb]<=0) do dec(Eb);

   if Ha<=Ea then
    if qA[Ha+1]>qA[Ha] then begin
     inc(Eb);
     qB[Eb]:=qA[Ha];
     inc(Ha);
    end;
  end;

  writeln(t);
  close(input);
  close(output);
 end.