CODE THAM KHẢO:
Program Thu_Vien;
Const fin = 'THUVIEN.INP';
fout = 'THUVIEN.OUT';
Var n,i,j,dem,kq,tam:Longint;
a,b,c,d:Array[1..200000] of Longint;
f:Text;
Begin
Assign(f,fin);
Reset(f);
Readln(f,n);
For i:=1 to n do Readln(f,a[i],b[i]);
Close(f);
For i:=1 to n do
Begin
c[i]:=a[i]; d[i]:=0;
c[n+i]:=b[i]; d[n+i]:=1;
End;
For i:=1 to 2*n do
For j:=i to 2*n do
If (c[i]>c[j]) or ((c[i]=c[j]) and (d[i]>d[j])) then
Begin
tam:=c[i]; c[i]:=c[j]; c[j]:=tam;
tam:=d[i]; d[i]:=d[j]; d[j]:=tam;
End;
kq:=0;
dem:=0;
For i:=1 to 2*n do
Begin
If d[i]=0 then dem:=dem+1
Else dem:=dem-1;
If dem>kq then kq:=dem;
End;
Assign(f,fout);
ReWrite(f);
Write(f,kq);
Close(f);
End.
Đăng nhận xét