比赛 20121023 评测结果 AAWAAAWATT
题目名称 奶牛晒衣服 最终得分 60
用户昵称 FrCsKOH 运行时间 2.871 s
代码语言 Pascal 内存使用 3.98 MiB
提交时间 2012-10-23 21:16:38
显示代码纯文本
  1. program C1210;
  2. const Be=500000;
  3. var qA,qB:array[1..Be] of longint;
  4. n,A,B,i,Ha,Ea,Hb,Eb,temp,t:longint;
  5. procedure down(i,m:longint);
  6. begin
  7. while i<<1<=m do begin
  8. i:=i<<1;
  9. if (i<m) and (qA[i]>qA[i+1]) then inc(i);
  10. if qA[i]<qA[i>>1] then begin
  11. temp:=qA[i];
  12. qA[i]:=qA[i>>1];
  13. qA[i>>1]:=temp;
  14. end else break;
  15. end;
  16. end;
  17.  
  18. procedure HeapSort;
  19. var i:longint;
  20. begin
  21. for i:=n>>1 downto 1 do down(i,n);
  22. for i:=n downto 2 do begin
  23. temp:=qA[i];
  24. qA[i]:=qA[1];
  25. qA[1]:=temp;
  26. down(1,i-1);
  27. end;
  28. end;
  29.  
  30. begin
  31. assign(input,'dry.in');
  32. reset(input);
  33. assign(output,'dry.out');
  34. rewrite(output);
  35.  
  36. readln(n,A,B);
  37. for i:=1 to n do read(qA[i]);
  38. readln;
  39.  
  40. HeapSort;
  41.  
  42. fillchar(qB,sizeof(qB),0);
  43. Ha:=1;
  44. Ea:=n;
  45. Hb:=1;
  46. Eb:=0;
  47. t:=0;
  48.  
  49. while not((Ha>Ea) and (Hb>Eb)) do begin
  50. inc(t);
  51. for i:=Ha to Ea do dec(qA[i],A);
  52. for i:=Hb to Eb do dec(qB[i],A);
  53. dec(qA[Ha],B);
  54.  
  55. while (Ha<=Ea) and (qA[Ea]<=0) do dec(Ea);
  56. while (Hb<=Eb) and (qB[Eb]<=0) do dec(Eb);
  57.  
  58. if Ha<=Ea then
  59. if qA[Ha+1]>qA[Ha] then begin
  60. inc(Eb);
  61. qB[Eb]:=qA[Ha];
  62. inc(Ha);
  63. end;
  64. end;
  65.  
  66. writeln(t);
  67. close(input);
  68. close(output);
  69. end.