记录编号 |
19895 |
评测结果 |
AAAATTTTTT |
题目名称 |
罪犯问题B |
最终得分 |
40 |
用户昵称 |
苏轼 |
是否通过 |
未通过 |
代码语言 |
Pascal |
运行时间 |
6.005 s |
提交时间 |
2010-10-19 09:57:38 |
内存使用 |
0.13 MiB |
显示代码纯文本
program criminalb(input,output);
var
i,j,n,m,k,wo,min,max,count:longint;
xe:array[0..1002,0..2]of longint;
tx,kmin:array[0..1002]of longint;
function mmm(a,b:longint):longint;
begin
if a>b then
exit(b)
else
exit(a);
end;
procedure go(wh,lie,sum:longint);
begin
inc(count);
if (lie<=k)and(wh<=n)and((sum+tx[wh]>max)or(sum<min))and(lie+kmin[wh]<=k) then
begin
if xe[wh,0]=0 then
go(wh+1,lie,sum)
else
begin
//he isn't
go(wh+1,lie+xe[wh,1],sum);
//he is
go(wh+1,lie+xe[wh,2],sum+xe[wh,0]);
end
end
else if (wh>n)and(lie<=k) then
begin
if sum<min then
min:=sum;
if sum>max then
max:=sum;
end;
end;
begin
assign(input,'criminalb.in');
reset(input);
assign(output,'criminalb.out');
rewrite(output);
readln(n,m,k);
for i:=1 to n do
read(xe[i,0]);
for i:=n downto 1 do
begin
tx[i]:=xe[i,0]+tx[i+1];
kmin[i]:=kmin[i+1]+mmm(xe[i,1],xe[i,2]);
end;
for i:=1 to m do
begin
readln(wo);
if (wo>0)and(xe[wo,0]=0) then
dec(k)
else
begin
if wo>0 then
inc(xe[wo,1])
else
inc(xe[-wo,2]);
end;
end;
min:=maxlongint;
go(1,0,0);
writeln(max);
writeln(min);
close(input);
close(output);
end.