比赛 NOIP2008集训模拟1 评测结果 WWWEAAEEWW
题目名称 地精贸易 最终得分 20
用户昵称 maxiem 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2008-11-10 11:12:56
显示代码纯文本
program goblin;
var
  thing:array [1..100] of record
    p,w,a,b:integer;
  end;
  sum:array [1..2,1..100] of integer;
  f:array [1..100000] of longint;
  v,max:longint;
  i,m:integer;
procedure cppack(no:integer);
var
  i,j:integer;
  flag:boolean;
  c:longint;
begin
  c:=0;
  for i:=1 to m do begin
    flag:=false;
    for j:=thing[i].p to v do if f[j]<=f[j-thing[i].p]+thing[i].w then begin
      f[j]:=f[j-thing[i].p]+thing[i].w;
       flag:=true;
    end;
    if flag then begin
      inc(sum[no,i],(f[v]-c) div thing[i].w);
      c:=f[v];
    end;
  end;
end;
begin
  fillchar (sum,sizeof(sum),0);
  fillchar (f,sizeof(f),0);
  assign (input,'goblin.in');
  reset (input);
  readln (v,m);
  max:=0;
  for i:=1 to m do readln (thing[i].a,thing[i].b);
  for i:=1 to m do begin
    thing[i].p:=thing[i].a;
    thing[i].w:=thing[i].b-thing[i].a;
  end;
  cppack(1);
  max:=max+f[v];
  fillchar (f,sizeof(f),0);
  for i:=1 to m do begin
    thing[i].p:=thing[i].b;
    thing[i].w:=thing[i].a-thing[i].b;
  end;
  v:=v+max;
  cppack(2);
  max:=max+f[v];
  close (input);
  assign (output,'goblin.out');
  rewrite (output);
  writeln (max);
  for i:=1 to m do begin
    if sum[1,i]<>0 then writeln ('Buy ',sum[1,i],' from Alliance') else begin
      if sum[2,i]<>0 then writeln ('Buy ',sum[2,i],' from Horde') else writeln ('Buy 0');
    end;
  end;
  close (output);
end.