Cod sursa(job #609730)

Utilizator ctlin04UAIC.VlasCatalin ctlin04 Data 23 august 2011 00:09:53
Problema Orase Scor 30
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.95 kb
Program orase;
type tip=record
         x,y:longint;
         end;
 var a:array [1..50005] of tip;
     b1:array [1..1 shl 10] of char;
     i,j,max,sol,n,d:longint;
     fi,fo:text;
procedure qsort(l,r:longint);
 var k,i,j:longint;
     y:tip;
 begin
  i:=l; j:=r;
   k:=a[(l+r) div 2].x;
 repeat
  while a[i].x<k do inc(i);
   while a[j].x>k do dec(j);
 if i<=j then
              begin
               y:=a[i];
                a[i]:=a[j];
                  a[j]:=y;
                     inc(i); dec(j);
              end;
 until i>=j;
  if l<j then qsort(l,j);
   if i<r then qsort(i,r);
 end;
begin
 assign(fi,'orase.in');
  assign(fo,'orase.out');
 settextbuf(fi,b1);
 reset(fi);
  rewrite(fo);
 readln(fi,n);
 for i:=1 to n do readln(fi,a[i].x,a[i].y);
 qsort(1,n);
 for i:=2 to n do begin
 if a[i-1].y-a[i-1].x>max then max:=a[i-1].y-a[i-1].x;
  d:=a[i].y+a[i].x+max;
 if d>sol then sol:=d;
 end;
write(fo,sol);
close(fo);
end.