| 比赛 | 
    20101101 | 
    评测结果 | 
    WWWWAWATTW | 
    | 题目名称 | 
    漂亮字串 | 
    最终得分 | 
    20 | 
    | 用户昵称 | 
    苏轼 | 
    运行时间 | 
    0.000 s  | 
    | 代码语言 | 
    Pascal | 
    内存使用 | 
    0.00 MiB  | 
    | 提交时间 | 
    2010-11-01 20:09:26 | 
显示代码纯文本
program bs(input,output);
var
  i,len,counto,countx,maxo,maxx,tmp,kkk:longint;
function min(a,b:longint):longint;
  begin
    if a>b then
      exit(b)
    else
      exit(a);
  end;
begin
  assign(input,'bs.in');
  reset(input);
  assign(output,'bs.out');
  rewrite(output);
  while not(eof) do
  begin
    readln(counto,countx,maxo,maxx);
    kkk:=min(counto,countx);
    len:=kkk*2;
    countx:=countx-kkk;
    for i:=1 to kkk do
    begin
      tmp:=min(countx,maxx-1);
      dec(countx,tmp);
      len:=len+tmp;
      if tmp+1>maxx then
      begin
        kkk:=0;
        len:=0;
        countx:=0;
        break;
      end;
    end;
    counto:=counto-kkk;
    for i:=1 to kkk do
    begin
      tmp:=min(counto,maxo-1);
      dec(counto,tmp);
      len:=len+tmp;
      if tmp+1>maxo then
      begin
        counto:=0;
        break;
      end;
    end;
    if countx>0 then
      len:=len+min(countx,maxx);
    if counto>0 then
      len:=len+min(counto,maxo);
    writeln(len);
  end;
  close(input);
  close(output);
end.