比赛 |
10.10.18noip模拟 |
评测结果 |
AAAWWWWWWW |
题目名称 |
罪犯问题B |
最终得分 |
30 |
用户昵称 |
ZhouZn1 |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2010-10-18 21:00:54 |
显示代码纯文本
program zzn;
var
m,n,i,kk,k,j,max,min:longint;
evil:array[1..1000]of integer;
w,peo2,c,peo:array[1..50000]of integer;
f:array[0..50001]of longint;
v,num:array[1..1000]of boolean;
procedure init;
begin
assign(input,'criminalb.in');
reset(input);
assign(output,'criminalb.out');
rewrite(output);
readln(n,m,kk);
max:=-1;min:=maxlongint;
for i:=1 to n do read(evil[i]);readln;
for i:=1 to m do readln(peo[i]);
end;
procedure closef;
begin
close(input);
close(output);
end;
procedure work;
var
x,i,s:longint;
begin
x:=0;s:=0;
for i:=1 to m do
begin
if peo[i]<0 then
if num[abs(peo[i])] then
begin
inc(x);
if x>kk then exit;
end;
if peo[i]>0 then
if not(num[peo[i]]) then
begin
inc(x);
if x>kk then exit;
end;
end;
for i:=1 to n do if num[i] then inc(s,evil[i]);
if s>max then max:=s;
if s<min then min:=s;
end;
procedure dep(x:integer);
begin
if x>n then
begin
work;
exit;
end;
num[x]:=true;
dep(x+1);
num[x]:=false;
dep(x+1);
end;
procedure main;
begin
fillchar(num,sizeof(num),0);
dep(1);
writeln(max);
writeln(min);
end;
function max2(a,b:longint):longint;
begin
if a>b then exit(a) else exit(b);
end;
function min2(a,b:longint):longint;
begin
if a<b then exit(a) else exit(b);
end;
procedure main2;
var
p,i,j:longint;
vv:array[-1000..1000]of integer;
begin
fillchar(f,sizeof(f),0);
fillchar(c,sizeof(c),0);
fillchar(v,sizeof(v),0);
p:=0;
fillchar(num,sizeof(num),0);
for i:=1 to m do
begin
if peo[i]<0 then
begin
if not(num[-peo[i]]) then
begin
num[-peo[i]]:=true;
inc(p);
peo2[p]:=peo[i];
vv[peo2[p]]:=p;
inc(c[p]);
end else
begin
inc(c[vv[peo[i]]]);
end;
end else if peo[i]>0 then
begin
if not(v[peo[i]]) then
begin
v[peo[i]]:=true;
inc(p);
peo2[p]:=peo[i];
vv[peo2[p]]:=p;
inc(c[p]);
end else inc(c[vv[peo[i]]]);
end;
end;//pre
fillchar(w,sizeof(w),0);
for i:=1 to p do
if peo2[i]>0 then w[i]:=evil[peo2[i]];
for i:=1 to p do
for j:=kk downto c[i] do
if f[j]<=f[j-c[i]]+w[i] then
f[j]:=f[j-c[i]]+w[i];
writeln(f[kk]);
end;
begin
init;
if n<=10 then
main else
main2;
closef;
end.