比赛 |
10.10.18noip模拟 |
评测结果 |
WWWWWWWWEE |
题目名称 |
罪犯问题B |
最终得分 |
0 |
用户昵称 |
maxiem |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2010-10-18 20:33:36 |
显示代码纯文本
program criminalb;
var
c:array [1..1000] of longint;
data:array [1..1000,-1..1] of longint;
dp:array [0..1000,0..10000] of longint;
k,i,n,m,t:longint;
procedure swap(a,b:longint);
var t:longint;
begin
t:=a;
a:=b;
b:=t;
end;
procedure get(no,w:longint);
var tmp:longint;
begin
if no=0 then dp[0,w]:=0 else begin
tmp:=0;
if w-data[no,-1]>=0 then begin
if dp[no-1,w-data[no,-1]]=-1 then get(no-1,w-data[no,-1]);
tmp:=dp[no-1,w-data[no,-1]]+c[no];
end;
if w-data[no,1]>=0 then begin
if dp[no-1,w-data[no,1]]=-1 then get(no-1,w-data[no,1]);
if dp[no-1,w-data[no,1]]>tmp then tmp:=dp[no-1,w-data[no,1]];
end;
dp[no,w]:=tmp;
end;
end;
procedure aget(no,w:longint);
var tmp:longint;
begin
if no=0 then dp[0,w]:=0 else begin
tmp:=maxlongint;
if w-data[no,-1]>=0 then begin
if dp[no-1,w-data[no,-1]]=-1 then aget(no-1,w-data[no,-1]);
tmp:=dp[no-1,w-data[no,-1]]+c[no];
end;
if w-data[no,1]>=0 then begin
if dp[no-1,w-data[no,1]]=-1 then aget(no-1,w-data[no,1]);
if dp[no-1,w-data[no,1]]<tmp then tmp:=dp[no-1,w-data[no,1]];
end;
dp[no,w]:=tmp;
end;
end;
begin
assign (input,'criminalb.in');
fillchar (dp,sizeof(dp),$FF);
fillchar (data,sizeof(data),0);
reset (input);
readln (n,m,k);
for i:=1 to n do read (c[i]);
for i:=1 to m do begin
readln (t);
if t>0 then inc(data[t,1]) else inc(data[-t,-1]);
end;
close (input);
assign (output,'criminalb.out');
rewrite (output);
get(n,k);
writeln (dp[n,k]);
fillchar (dp,sizeof(dp),$FF);
aget(n,k);
writeln (dp[n,k]);
close (output);
end.