比赛 20100913 评测结果 AWWWWWWWWW
题目名称 越狱 最终得分 10
用户昵称 maxiem 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2010-09-13 22:10:37
显示代码纯文本
program prisonbreak;
var
  dp,a,b:array [0..10001] of longint;
  n,i:longint;
procedure get(num,o:longint);
var oil,i:longint;
begin
  if num<>0 then begin
    i:=num;o:=o+b[num];
    repeat
	  i:=i-1;oil:=o-(a[num]-a[i]);
	  if oil>=0 then begin
            get(i,oil);
	    if dp[num]>dp[i] then dp[num]:=dp[i]+1;
          end;
	until (i=0) or (oil<0);
  end;
end;
begin
  assign (input,'prisonbreak.in');
  reset (input);
  readln (n);
  fillchar (a,sizeof(a),0);
  fillchar (b,sizeof(b),0);
  for i:=1 to n+1 do readln (a[i],b[i]);
  close (input);
  assign (output,'prisonbreak.out');
  rewrite (output);
  for i:=0 to n+1 do dp[i]:=maxlongint;
  dp[0]:=0;
  get(n+1,0);
  writeln (dp[n+1]-1);
  close (output);
end.