比赛 小练习赛:B组 评测结果 AWAAWEEEEAE
题目名称 纪念品分组 最终得分 36
用户昵称 safhsdajkfhsad 运行时间 0.470 s
代码语言 Pascal 内存使用 0.21 MiB
提交时间 2014-10-21 19:59:39
显示代码纯文本
const
  maxnum=10000;
type
  tdata=array[0..maxnum] of longint;
var
  n,w,i,j,vans,vuse:longint;
  data:tdata;
  dause:array[0..maxnum] of boolean;

procedure gcqsort(var data:tdata; st,en:longint);
  var
    i,j,mid,temp:longint;
  begin
    i:=st;
    j:=en;
    mid:=data[(st+en) div 2];

    while (i<=j) do
      begin
        while (data[i]<mid) do
          inc(i);
        while (data[j]>mid) do
          dec(j);
        if (i<=j) then
          begin
            mid:=data[i];
            data[i]:=data[j];
            data[j]:=mid;
            inc(i);
            dec(j);
          end;
      end;

    if (st<j) then
      gcqsort(data,st,j);
    if (i<en) then
      gcqsort(data,i,en);
  end;

begin
  assign(input,'group.in');
  reset(input);
  assign(output,'group.out');
  rewrite(output);
  readln(w);
  readln(n);
  fillchar(dause,sizeof(dause),true);

  for i:=1 to n do
    readln(data[i]);

  gcqsort(data,1,n);

  vans:=0;

  for i:=n downto 1 do
    if (dause[i]) then
    begin
      dause[i]:=false;
      inc(vans);
      for j:=1 to n do
       if (data[j]+data[i]<=w) and (dause[j]) then
         dause[j]:=false;
    end;

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