| 比赛 | 
    20101101 | 
    评测结果 | 
    AAAAAAAAAA | 
    | 题目名称 | 
    漂亮字串 | 
    最终得分 | 
    100 | 
    | 用户昵称 | 
    wo shi 刘畅 | 
    运行时间 | 
    0.000 s  | 
    | 代码语言 | 
    Pascal | 
    内存使用 | 
    0.00 MiB  | 
    | 提交时间 | 
    2010-11-01 20:06:06 | 
显示代码纯文本
var
  s1,s2,t1,t2,f,total,t:longint;
function min(x,y:longint):longint;
begin
  if x<y then exit(x);
  exit(y);
end;
begin
  assign(input,'bs.in'); reset(input);
  assign(output,'bs.out'); rewrite(output);
  while not eof do
  begin
    readln(s1,s2,t1,t2);
    if (t1=0)and(t2=0) then writeln(0)
    else if (t1=0)and(t2>0) then writeln(min(t2,s2))
    else if (t1>0)and(t2=0) then writeln(min(t1,s1))
    else begin
      if s1>s2 then
      begin
        t:=s1;
        s1:=s2;
        s2:=t;
        t:=t1;
        t1:=t2;
        t2:=t;
      end;
      total:=0;
      total:=2*s1;
      s2:=s2-s1;
      f:=min(t2,s2);
      inc(total,f);
      dec(s2,f);
      t:=0;
      while (s2>0)and(t<s1) do
      begin
        f:=min(t2-1,s2);
        inc(total,f);
        dec(s2,f);
        inc(t);
      end;
      writeln(total);
    end;
  end;
  close(input);
  close(output);
end.