记录编号 |
468312 |
评测结果 |
AAAAAAAAAA |
题目名称 |
情敌 |
最终得分 |
100 |
用户昵称 |
Jekyll |
是否通过 |
通过 |
代码语言 |
Pascal |
运行时间 |
0.173 s |
提交时间 |
2017-10-31 20:59:05 |
内存使用 |
0.25 MiB |
显示代码纯文本
var
i,j,k,m,n,aa,bb,a,b,c,tot:longint;
first,ans,sum:int64;
su:array[0..51] of longint;
t,v:array[0..51] of longint;
f:array[0..101,0..101] of int64;
bao:array[0..51,0..51] of longint;
d:array[0..51] of longint;
can1,can2,ss:array[0..51] of boolean;
procedure init;
begin
fillchar(ss,sizeof(ss),true);
fillchar(su,sizeof(su),0);
fillchar(bao,sizeof(bao),0);
readln(a,b);
b:=b shr 1;
readln(n,m);
for i:=1 to n do
begin
readln(v[i],t[i]);
inc(sum,v[i]);
end;
for i:=1 to m do
begin
read(c,tot);
ss[c]:=false;
inc(su[0]);
su[su[0]]:=c;
bao[c,0]:=tot;
for j:=1 to tot do
begin
read(bao[c,j]);
end;
readln;
end;
end;
procedure done;
var
i,j,k:longint;
begin
fillchar(can1,sizeof(can1),true);
fillchar(can2,sizeof(can2),true);
aa:=0;
bb:=0;
first:=0;
for i:=1 to m do
case d[i] of
0:begin
for j:=1 to bao[su[i],0] do
begin
can1[bao[su[i],j]]:=false;
can2[bao[su[i],j]]:=false;
end;
end;
1:begin
aa:=aa+t[su[i]];
first:=first+v[su[i]];
if aa>a then exit;
for j:=1 to bao[su[i],0] do
begin
can1[bao[su[i],j]]:=true;
can2[bao[su[i],j]]:=true;
end;
end;
2:begin
bb:=bb+t[su[i]];
first:=first+v[su[i]];
if bb>b then exit;
for j:=1 to bao[su[i],0] do
begin
can1[bao[su[i],j]]:=false;
can2[bao[su[i],j]]:=true;
end;
end;
end;
fillchar(f,sizeof(f),0);
for i:=1 to n do
if ss[i] then
begin
for j:=a downto aa do
for k:=b downto bb do
begin
if (can1[i]) and (j-t[i]>=aa) then
if f[j-t[i],k]+v[i]>f[j,k] then f[j,k]:=f[j-t[i],k]+v[i];
if (can2[i]) and (k-t[i]>=bb) then
if f[j,k-t[i]]+v[i]>f[j,k] then f[j,k]:=f[j,k-t[i]]+v[i];
end;
end;
if ans<f[a,b]+first then ans:=f[a,b]+first;
end;
procedure find(t:longint);
var
ii:longint;
begin
for ii:=0 to 2 do
begin
d[t]:=ii;
if t=m then done else find(t+1);
end;
end;
procedure main;
begin
if m>0 then find(1)
else done;
writeln(sum-ans);
end;
begin
assign(input,'rival.in');reset(input);
assign(output,'rival.out');rewrite(output);
ans:=0;
init;
main;
close(input);
close(output);
end.