比赛 |
10.10.18noip模拟 |
评测结果 |
WWWWWTTTTT |
题目名称 |
罪犯问题B |
最终得分 |
0 |
用户昵称 |
Achilles |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2010-10-18 20:54:26 |
显示代码纯文本
program criminalb;
var
n,m,k,nowk,xe,xet,i,i2,j,temp,temp2:longint;
a:array[0..1000]of longint;
b:array[0..1000,1..3]of longint;
tab:array[0..1000,0..1000,1..2]of longint;{lie and xe}
begin
assign(input,'criminalb.in');
assign(output,'criminalb.out');
reset(input);
rewrite(output);
readln(n,m,k);
for i:=1 to n do
read(a[i]);
readln;
fillchar(b,sizeof(b),0);
for i:=1 to n do
b[i,1]:=1;
xe:=0;
for i:=1 to m do
begin
readln(temp);
if temp>0 then b[temp,2]:=b[temp,2]+1 else b[-temp,3]:=b[-temp,3]+1;
end;
nowk:=0;
for i:=1 to n do
begin
if b[i,2]>=b[i,3] then begin
xe:=xe+a[i]*b[i,2];
nowk:=nowk+b[i,3];
end
else begin
temp:=b[i,2];
b[i,2]:=b[i,3];
b[i,3]:=temp;
b[i,1]:=-1;
xe:=xe+a[i]*b[i,2];
nowk:=nowk+b[i,3];
end;
end;
{ for i:=1 to n-1 do
for j:=i+1 to n do
if a[i]<a[j] then begin
a[0]:=a[i];
a[i]:=a[j];
a[j]:=a[0];
b[0]:=b[i];
b[i]:=b[j];
b[j]:=b[0];
end;}
fillchar(tab,sizeof(tab),0);
for i:=1 to n do
begin
tab[i,0,1]:=tab[i-1,0,1]+b[i,3];
if b[i,1]=1 then tab[i,0,2]:=tab[i-1,0,2]+a[i] else tab[i,0,2]:=tab[i-1,0,2];
end;
a[0]:=0;
for i:=1 to n do
if b[i,1]=-1 then begin
for j:=1 to i do
begin
for i2:=i-1 downto 0 do
begin
if i2<j then break;
tab[i,j,1]:=tab[i2,j-1,1]+tab[i,0,1]-tab[i2,0,1];
tab[i,j,2]:=tab[i2,j-1,2]+tab[i,0,2]-tab[i2,0,2];
if (tab[i2,j,1]+b[i,3]<=k)and(tab[i2,j,2]+a[i]>tab[i,j,2]) then begin
tab[i,j,2]:=tab[i2,j,2]+a[i];
tab[i,j,1]:=tab[i2,j,1]+b[i,3];
end;
end;
end;
end;
temp:=0;
for i:=1 to n do
for j:=0 to i do
if (tab[i,j,1]<=k)and(tab[i,j,2]>temp) then temp:=tab[i,j,2];
writeln(temp);
for i:=1 to n do
if (b[i,1]=1)and(b[i,2]=b[i,3]) then b[i,1]:=-1;
fillchar(tab,sizeof(tab),0);
for i:=1 to n do
begin
tab[i,0,1]:=tab[i-1,0,1]+b[i,3];
if b[i,1]=1 then tab[i,0,2]:=tab[i-1,0,2]+a[i] else tab[i,0,2]:=tab[i-1,0,2];
end;
a[0]:=0;
for i:=1 to n do
if b[i,1]=-1 then begin
for j:=1 to i do
begin
for i2:=i-1 downto 0 do
begin
if i2<j then break;
tab[i,j,1]:=tab[i2,j-1,1]+tab[i,0,1]-tab[i2,0,1];
tab[i,j,2]:=tab[i2,j-1,2]+tab[i,0,2]-tab[i2,0,2];
if (tab[i,j,1]+b[i,3]<=k)and(tab[i,j,2]-a[i]<tab[i,j,2]) then begin
tab[i,j,2]:=tab[i2,j-1,2]-a[i];
tab[i,j,1]:=tab[i2,j,1]+b[i,3];
end;
end;
end;
end;
temp:=2000000000;
for i:=1 to n do
for j:=0 to i-1 do
if (tab[i,j,1]<=k)and(tab[i,j,2]<temp) then temp:=tab[i,j,2];
writeln(temp);
close(input);
close(output);
end.