比赛 20101118 评测结果 AWWWWWWWWW
题目名称 情敌 最终得分 10
用户昵称 donny 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2010-11-18 10:26:37
显示代码纯文本
program rival;
var
  i,j,k,l:longint;
  a,b,n,m:longint;
  p:array[1..50,1..3]of longint;
  q:array[1..10,1..50]of longint;
  f:array[0..50,0..202]of longint;
  weixie:longint;
begin
  assign(input,'rival.in');
  reset(input);
  assign(output,'rival.out');
  rewrite(output);
  readln(a,b);
  readln(n,m);
  for i:=1 to n do
  begin
    readln(p[i,1],p[i,2]);
    weixie:=weixie+p[i,1];
  end;
  for i:=1 to n do
    for j:=1 to a+b do
    begin
      f[i,j]:=f[i-1,j];
      if (j<=a)and((j-p[i,2])>=0) then
      begin
        if f[i-1,j-p[i,2]]+p[i,1]>f[i,j] then
          f[i,j]:=f[i-1,j-p[i,2]]+p[i,1];
      end
      else
        if (j>a)and((j-2*p[i,2])>=a) then
        begin
          if f[i-1,j-2*p[i,2]]+p[i,1]>f[i,j] then
            f[i,j]:=f[i-1,j-2*p[i,2]]+p[i,1];
        end;
    end;
  writeln(weixie-f[n,a+b]);
  close(input);
  close(output);
end.