All pastes #1971438 Raw Edit

soda

public text v1 · immutable
#1971438 ·published 2010-10-24 02:21 UTC
rendered paste body
//uses sysutils;
type re=record
        num:longint;
        flag:longint;
      end;
var i,j,k,m,n,count,s,e,max:longint;
    t1:tdatetime;
    a:array[0..1000001] of re;
procedure qsort( s,t:longint);
var i,j,k,p:longint;
    temp:re;
begin
  if s>=t then exit;
  p:=s+(t-s)div 2;
  i:=s;j:=t;
  temp:=a[p];a[p]:=a[s];
  repeat
    while(i<j) and(a[j].num>=temp.num) do
      dec(j);
      if i=j then break;
      a[i]:=a[j];
      inc(i);
    while (i<j) and(a[i].num<=temp.num) do
      inc(i);
      if i=j then break;
      a[j]:=a[i];
      dec(j);
    until i=j;
    a[i]:=temp;
    qsort(s,i-1);qsort(i+1,t);
end;
begin
  //t1:=now;
  assign(input,'soda.in');reset(input);
  readln(n);
  for i:=1 to n do begin
    readln(a[2*i-1].num,a[2*i].num);
    a[2*i-1].flag:=0;
    a[2*i].flag:=1;
  end;
  qsort(1,2*n);count:=0;i:=1;
  while i<=2*n do begin
    j:=i;
    s:=0;
    e:=0;
    while a[j].num=a[i].num do begin
      if a[j].flag=0 then inc(s) else inc(e);
      inc(j);
    end;
    dec(j);
    for k:=i to j do begin
      if s>0 then begin
        a[k].flag:=0;dec(s);
       end
      else a[k].flag:=1;
    end;
    i:=j+1;
  end;
  //for i:=1 to 2*n do writeln(a[i].num,' ',a[i].flag);
  count:=0;max:=0;
  for i:=1 to 2*n do begin
    if a[i].flag=0 then inc(count) else dec(count);
    if count>max then max:=count;
  end;
  writeln(max);
  //writeln((now-t1)*86400:0:2);
  close(input);
end.