比赛 20101101 评测结果 AAAAAAAAAA
题目名称 漂亮字串 最终得分 100
用户昵称 Achilles 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2010-11-01 19:25:39
显示代码纯文本
program bs;
var
  counto,countx,maxo,maxx,ans,temp:longint;
begin
  assign(input,'bs.in');
  assign(output,'bs.out');
  reset(input);
  rewrite(output);
  while not eof do
  begin
    readln(counto,countx,maxo,maxx);
    if (maxo=0)and(maxx=0) then writeln(0);
    if (maxo=0)and(maxx<>0) then
      if maxx<countx then writeln(maxx) else writeln(countx);
    if (maxo<>0)and(maxx=0) then
      if maxo<counto then writeln(maxo) else writeln(counto);
    if (maxo<>0)and(maxx<>0) then begin
      if counto>countx then begin
        temp:=countx+1;
        ans:=countx*2;
        counto:=counto-countx;
        if counto>0 then begin
          counto:=counto-1;
          ans:=ans+1;
        end;
        if maxo>1 then if counto/(maxo-1)<=temp then ans:=ans+counto else ans:=ans+temp*(maxo-1);
      end
      else begin
        temp:=counto+1;
        ans:=counto*2;
        countx:=countx-counto;
        if countx>0 then begin
          countx:=countx-1;
          ans:=ans+1;
        end;
        if maxx>1 then if countx/(maxx-1)<=temp then ans:=ans+countx else ans:=ans+temp*(maxx-1);
      end;
      writeln(ans);
    end;
  end;
  close(input);
  close(output);
end.