比赛 NOIP2008集训模拟2 评测结果 C
题目名称 美酒节赛羊 最终得分 0
用户昵称 NOIer 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2008-11-11 11:14:34
显示代码纯文本
Program Goat;
Const
   MaxN  =  300000;
   Inf   =  'goat.in';
   Ouf   =  'goat.out';
Var
   Value :  Array[-20..MaxN,-10..120] of Longint;
   s,p   :  Longint;

Function Little(x,y:Longint):Longint;
   Begin
      Little:=MaxLongint;
      if x<little then Little:=x;
      if y<little then Little:=y;
   End;

Procedure Init;
   Begin
      assign(input,Inf); reset(input);
      assign(output,Ouf); rewrite(output);
      FilldWord(Value,sizeof(Value) div 4,25000000);
      Value[0][0]:=0;
      Readln(s,p);
   End;


Procedure Main;
   Var
      i,j:Longint;
      Sum,k:Longint;
   Begin
      Begin
      For i:=1 to s do
      Begin
        For j:=1 to p do
          Begin
            Sum:=maxlongint;
            if j=p-10 then
              Begin
                k:=Little(Value[i-1,j+1]+1,Little(Value[i-5,j-2]+1,Little(Value[i-10,j-5]+1,Value[i-10,j]+10)));
                if k<Sum then
                  Sum:=k;
              End
            Else
              Begin
                k:=Little(Value[i-1,j+1]+1,Little(Value[i-5,j-2]+1,Value[i-10,j-5]+1));
                if j<Sum then
                  Sum:=k;
              End;
            Value[i,j]:=Sum;
          End;

      End;
      End;
   End;

Procedure Print;
   Begin
      writeln(Value[s][p]);
      close(input);
      close(output);
   End;

BEGIN
   Init;
   Main;
   print;
END.