记录编号 20137 评测结果 AAAAAAAAAT
题目名称 罪犯问题B 最终得分 90
用户昵称 Gravatarreamb 是否通过 未通过
代码语言 Pascal 运行时间 2.323 s
提交时间 2010-10-20 21:27:24 内存使用 0.89 MiB
显示代码纯文本
program zuifanwentib;
var
  i,j,n,m,k,x,y,max,min,z,zz:longint;
  f1,f2:array[0..1,0..50000] of longint;
  a,s,b:array[1..1000]of longint;
begin
  assign (input,'criminalb.in');
  reset (input);
  assign (output,'criminalb.out');
  rewrite (output);
    readln (n,m,k);
    for i:=1 to n do
      read (a[i]);
    readln;
    for i:=1 to m do
    begin
      readln (x);
      if x>0 then
        s[x]:=s[x]+1
      else
        b[-x]:=b[-x]+1
    end;
    for i:=1 to n do
    begin
      x:=(i+1)and 1;
      y:=i and 1;
      for j:=0 to k do
      begin
        max:=-maxlongint;
        if j>=b[i] then
          max:=f1[x,j-b[i]]+a[i];
        if j>=s[i] then
        begin
          z:=f1[x,j-s[i]];
          if z>max then
            max:=z
        end;
        f1[y,j]:=max
      end
    end;
    for i:=1 to n do
    begin
      x:=(i+1)and 1;
      y:=i and 1;
      for j:=0 to k do
      begin
        min:=maxlongint;
        if (j>=b[i])then
        begin
          z:=f2[x,j-b[i]];
          if z<>maxlongint then
            min:=z+a[i]
        end;
        if (j>=s[i]) then
        begin
          zz:=f2[x,j-s[i]];
          if (zz<>maxlongint)and(zz<min) then
            min:=zz
        end;
        f2[y,j]:=min
      end
    end;
    writeln (f1[n mod 2,k]);
    writeln (f2[n mod 2,k]);
  close (input);
  close (output)
end.