记录编号 48842 评测结果 AAAAAAAA
题目名称 过河 最终得分 100
用户昵称 Gravatarwarrior 是否通过 通过
代码语言 Pascal 运行时间 0.051 s
提交时间 2012-11-06 18:48:51 内存使用 0.17 MiB
显示代码纯文本
var n,i,ans,time,j:longint;
    a,b:array[0..1000]of longint; nv,lv:Array[0..1000]of boolean;
    f:boolean;
function check(t,i:longint):boolean;
begin
 if (i=0)or(i=n+1) then exit(true);
 if (t mod (a[i]+b[i])>0)and(t mod (a[i]+b[i])<=a[i])then exit(true)
 else exit(false);
end;

begin
assign(input,'rivera.in');assign(output,'rivera.out');
reset(input);rewrite(output);
 ans:=maxlongint; fillchar(lv,sizeof(lv),0);
 readln(n); for I:=1 to n  do readln(a[i],b[i]);
 time:=0;  lv[0]:=true;
 repeat
  inc(time);f:=false;
  fillchar(nv,sizeof(nv),0);
  for i:=0 to n+1 do if check(time,i) then
   for j:=i-5 to i+5 do
    if (j>=0)and(j<=n+1)and(lv[j]) then nv[i]:=true;
  if nv[n+1]then begin ans:=time;break;end;
  //for i:=0 to n+1 do if nv[i]then write(i,' ');writeln;
  lv:=nv;  //if f=false then break;
 until time>2555;

 if ans>100000 then writeln('NO') else writeln(ans);
 close(output);
end.