比赛 20101105 评测结果 AAAAAAAAAA
题目名称 懒人的工作 最终得分 100
用户昵称 绝对零度 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2010-11-05 21:30:04
显示代码纯文本
 var m:array[1..10001] of integer;
    p,t,a,b:array[1..10001] of integer;
    n,k,i,j,len:integer;
procedure pai(x:integer);
var t2,y,t1:integer;
begin
    while (x*2<=len)and(a[x]>a[x*2])or((x*2+1<=LEN)and(A[X]>A[X*2+1])) do begin
       if x*2=len then y:=x*2
       else if a[x*2]<a[x*2+1] then y:=x*2 else y:=x*2+1;
       t2:=a[y];a[y]:=a[x];a[x]:=t2;
       t1:=b[y];b[y]:=b[x];b[x]:=t1;x:=y;
    end;
end;
procedure delete;
begin
    a[1]:=a[len];
    b[1]:=b[len];
    dec(len);
    pai(1);
end;
begin
    assign(input,'lazy.in');
    reset(input);
    assign(output,'lazy.out');
    rewrite(output);
    readln(n,k);
    for i:=1 to k do begin
     readln(p[i],t[i]);
     a[i]:=p[i];b[i]:=t[i];
    end;
    len:=k;
    for i:=k div 2 downto 1 do pai(i);
    for i:=1 to k do begin
    p[i]:=a[1];t[i]:=b[1];
     delete;
    end;
    m[n+1]:=0;j:=k;
    for i:=n downto 1 do begin
      if p[j]<>i then m[i]:=m[i+1]+1 else
      while p[j]=i do begin
        if m[i+t[j]]>m[i] then begin
         m[i]:=m[i+t[j]]
        end;
        j:=j-1;
      end;
    end;
    writeln(m[1]);
    close(input);
    close(output);
end.