比赛 20101118 评测结果 AWWWWWWWWW
题目名称 情敌 最终得分 10
用户昵称 wo shi 刘畅 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2010-11-18 10:53:29
显示代码纯文本
var
  a,total,i,j,max,b,n,m,tot,c:longint;
  pp,p,w:array[0..10000]of longint;
  f:Array[0..10000]of boolean;

procedure go(s,num:longint);
var
  i:longint;
begin
  if num>max then max:=s;
  for i:=1 to n do
  if not f[i] then
  begin
    if s+w[i]<=a then
    begin
      f[i]:=true;
      go(s+w[i],num+p[i]);
      f[i]:=false;
    end;
    if (s>a)and(s+w[i]+w[i]<=a+b) then
    begin
      f[i]:=true;
      go(s+w[i]+w[i],num+p[i]);
      f[i]:=false;
    end;
  end;
end;

begin
  assign(input,'rival.in'); reset(input);
  assign(output,'rival.out'); rewrite(output);
  readln(a,b);
  readln(n,m);
  if m=0 then
  begin
    for i:=1 to n do
    begin
      readln(p[i],w[i]);
      inc(total,p[i]);
    end;
    for i:=1 to m do
    begin
      read(c,tot);
      for j:=1 to tot do read(pp[j]);
    end;
    go(0,0);
    writeln(total-max);
  end
  else writeln(0);
  close(input);
  close(output);
end.