比赛 10.10.18noip模拟 评测结果 WAWAWAAATT
题目名称 罪犯问题B 最终得分 50
用户昵称 reamb 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2010-10-18 21:22:44
显示代码纯文本
program zuifanweitib;
var
  f1,f2:array[0..1,0..50000]of longint;
  i,j,n,m,k,x,y,max,min:longint;
  a:array[1..50000]of longint;
  r1,r2: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
        r1[x]:=r1[x]+1
      else
        r2[-x]:=r2[-x]+1
    end;
    for i:=1 to n do
    begin
      x:=i mod 2;
      y:=(i+1)mod 2;
      for j:=0 to k  do
      begin
        max:=0;
        if j>=r1[i] then
          max:=f1[y,j-r1[i]];
        if (j>=r2[i])and(f1[y,j-r2[i]]+a[i]>max) then
          max:=f1[y,j-r2[i]]+a[i];
        f1[x,j]:=max;
      end
    end;
    for i:=1 to n do
    begin
      x:=i mod 2;
      y:=(i+1)mod 2;
      for j:=0 to k  do
      begin
        min:=maxlongint;
        if j>=r1[i] then
          min:=f2[y,j-r1[i]];
        if (j>=r2[i])and(f2[y,j-r2[i]]<>maxlongint)
        and(f2[y,j-r2[i]]+a[i]<min) then
          min:=f2[y,j-r2[i]]+a[i];
        f2[x,j]:=min
      end
    end;
    max:=0;
    min:=maxlongint;
    for i:=0 to k do
      if f1[n mod 2,i]>max then
        max:=f1[n mod 2,i];
    for i:=0 to k do
      if f2[n mod 2,i]<min then
        min:=f2[n mod 2,i];
    writeln (max);
    writeln (min);
  close (input);
  close (output)
end.