记录编号 7666 评测结果 WEEEEWWWEE
题目名称 地精贸易 最终得分 0
用户昵称 GravatarEnAsn 是否通过 未通过
代码语言 Pascal 运行时间 0.062 s
提交时间 2008-11-10 22:18:30 内存使用 0.43 MiB
显示代码纯文本
program ex;
type
 zs=array[0..100]of longint;
 ss=array[1..100]of longint;
 sz=array[-10..400]of zs;
var
 a,h,map:ss;
 f,g:sz;
 f1,f2:text;
 n,m:integer;
procedure init;
 var
  i:integer;
 begin
  assign(f1,'goblin.in');
  assign(f2,'goblin.out');
  reset(f1);
  rewrite(f2);
  readln(f1,n,m);
  for i:=1 to m do
   readln(f1,a[i],h[i]);
  close(f1);
 end;
function pd(c,d:zs;max:integer):boolean;
 var
  i:integer;
 begin
  pd:=false;
  for i:=1 to  max do
   begin
    if c[i]>d[i] then
      begin
       pd:=false;
       break;
      end;
    if c[i]<d[i] then
      begin
       pd:=true;
       break;
      end;
   end;
 end;
procedure main1;
 var
  i,j,k:integer;
 begin
  for i:=1 to n do
   for j:=1 to m do
    if i-a[j]>0 then
     if f[i-a[j]][0]-a[j]+h[j]>=f[i][0] then
      begin
       f[i][0]:=f[i-a[j]][0]-a[j]+h[j];
       {if (pd(f[i],f[i-a[j]],i)=true)or(f[i][0]<>0) then
        begin}
         for k:=1 to m do
          f[i][k]:=f[i-a[j]][k];
         inc(f[i][j]);
       {end;}
      end;
  for i:=0 to m do
   write(f2,f[n][i],' ');
  writeln(f2);
 end;
procedure main2;
 var
  i,j,k:integer;
 begin
  for i:=1 to n+f[n][0] do
   for j:=1 to m do
    if i-h[j]>0 then
     if g[i-h[j]][0]-h[j]+a[j]>=g[i][0] then
      begin
       g[i][0]:=g[i-h[j]][0]-h[j]+a[j];
       {if (pd(g[i],g[i-h[j]],i)=true)or(g[i][0]<>0) then
        begin}
         for k:=1 to m do
          g[i][k]:=g[i-h[j]][k];
         inc(g[i][j]);
       {end;}
      end;
  for i:=0 to m do
   write(f2,g[n+f[n][0]][i],' ');
  writeln(f2);
 end;
begin
 init;
 main1;
 main2;
 writeln(f2,f[n][0]+g[f[n][0]+n][0]);
 close(f2);
end.