Thứ Ba, 3 tháng 5, 2022

THUOCDOAN PASCAL

const
        fin='thuocdoan.inp';fon='thuocdoan.out';
maxn=100000;

type pt=record
   gt,loai:longint;
end;
var
   c:array[0..2*maxn] of pt;
   n:longint;

procedure enter;
var i,h:longint;
begin
    readln(n);
    for i:=1 to n do
       begin
           readln(c[2*i-1].gt,c[2*i].gt);
           c[2*i-1].loai:=0;
           c[2*i].loai:=1;
       end;
end;

function ss(x,y:pt):boolean;
begin
    if x.gt<y.gt then exit(true);
    if x.gt>y.gt then exit(false);
    if x.loai < y.loai then exit(true);
    if x.loai > y.loai then exit(false);
    exit(false);
end;


procedure qs_c(l,h:longint);
var i,j:longint;
      x,t:pt;
begin
    x:=c[(l+h) div 2];
    i:=l;j:=h;
    repeat
         while ss(c[i],x)=true do inc(i);
         while ss(x,c[j])=true do dec(j);
         if i<=j then
         begin
            t:=c[i];c[i]:=c[j];c[j]:=t;
            inc(i);dec(j);
         end;
    until i>j;
    if L<j then qs_c(L,j);
    if i<H then qs_c(i,H);
end;

procedure solve;
var i,count,max:longint;
begin
    qs_c(1,2*n);
 //   for i:=1 to 2*n do
  //      write(c[i].gt,' ');
  //  writeln;
    count:=0;max:=0;
    for i:=1 to 2*n do
       begin
           if c[i].loai=0 then inc(count) else dec(count);
           if count>max then max:=count;
       end;
   writeln(max);
end;

begin
    assign(input,fin);reset(input);
    assign(output,fon);rewrite(output);
    enter;
    solve;
    close(input);close(output);
end.

Không có nhận xét nào:

Đăng nhận xét

Lưu ý: Chỉ thành viên của blog này mới được đăng nhận xét.