比赛 2008haoi模拟训练3 评测结果 AAAAATTTTT
题目名称 阶梯教室设备利用 最终得分 50
用户昵称 E.M.B.E.R 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2008-04-24 09:49:01
显示代码纯文本
program EmberAsh;
 type
  re=record
   u,w:longint;
 end;
var
 i,j,k,m,n:longint;
 b:array[0..10000]of longint;
 a:array[1..10000]of re;
 fin,fout:Text;
procedure init;
 begin
  assign(fin,'rez.in');
  reset(fin);
  assign(fout,'rez.out');
  rewrite(fout);
  read(fin,n);
  for i:=1 to n do
   readln(fin,a[i].u,a[i].w);
 end;

 procedure qsort(lx,rx:longint);
 var
  i,j,t1,t2:longint;
 begin
  i:=lx;j:=rx;t1:=a[i].u;t2:=a[i].w;
   repeat
    while  (i<j) and(t1<a[j].u) do
     j:=j-1;
      if i<j then
       begin
        a[i].u:=a[j].u;
        a[i].w:=a[j].w;
        i:=i+1;
         while (i<j) and(t1>a[i].u) do
          i:=i+1;
           if i<j then
            begin
             a[j].u:=a[i].u;
             a[j].w:=a[i].w;
             j:=j-1;
            end;
       end;
    until i=j;
   a[i].w:=t2;a[i].u:=t1;i:=i+1;j:=j-1;
 if i<rx then qsort(i,rx);
 if j>lx then qsort(lx,j);
end;
procedure make;
 begin
 for i:=1 to n do
  b[i]:=a[i].w-a[i].u;
   for i:=2 to n do
    for j:=1 to i do
     begin
      if a[i].u>=a[j].w then
       begin
        k:=b[j]+a[i].w-a[i].u;
         if k>b[i] then
          b[i]:=k;
        end;
     end;
 end;
begin
 init;
 qsort(1,n);
 make;
 j:=0;
 for i:=1 to n do
  if b[i]>j then
   j:=b[i];
 writeln(fout,j);
 close(fout);
 close(fin);
end.