比赛 10.10.18noip模拟 评测结果 AAATTTTTTT
题目名称 罪犯问题A 最终得分 30
用户昵称 make 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2010-10-18 19:56:47
显示代码纯文本
program criminala;
var
 a:array [1..50000] of longint;
 h1,h2:array [1..1000] of longint;
 n,m,max,min:longint;
 f1,f2:text;

procedure init;
var i:longint;
begin
 assign(f1,'criminala.in'); reset(f1);
 assign(f2,'criminala.out'); rewrite(f2);
 readln(f1,n,m);
 for i:=1 to m do begin
  readln(f1,a[i]);
  if a[i]>0 then inc(h1[a[i]])
  else inc(h2[abs(a[i])]);
 end;
 close(f1);
 max:=0;
 min:=1001;
end;

procedure dfs(x,total:longint);
var r:longint;
begin
 if x=n+1 then begin
              if total>max then max:=total;
              if total<min then min:=total;
             end
 else begin
  for r:=1 to 2 do begin
   if r=1 then begin
    dfs(x+1,total+h2[x]);
   end;
   if r=2 then begin
    dfs(x+1,total+h1[x]);
    end;
  end;
 end;
end;

begin
 init;
 dfs(1,0);
 writeln(f2,max);
 writeln(f2,min);
 close(f2);
end.