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

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

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

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