#include<fstream>
using namespace std;
ifstream fin("date.in");
ofstream fout("date.out");
struct interval {int a,b;};
void citire(interval &x)
{
fin>>x.a>>x.b;
}
void afisare(interval x)
{
fout<<"["<<x.a<<","<<x.b<<"] ";
}
void ordonarea(int n, interval x[100])
{
int i,gata;
interval aux;
do
{
gata=1;
for(i=1;i<n;i++)
if(x[i].a>x[i+1].a)
{
aux=x[i];
x[i]=x[i+1];
x[i+1]=aux;
gata=0;
}
}
while(!gata);
}
void ordonareb(int n, interval x[100])
{
int i,gata;
interval aux;
do
{
gata=1;
for(i=1;i<n;i++)
if(x[i].b>x[i+1].b)
{
aux=x[i];
x[i]=x[i+1];
x[i+1]=aux;
gata=0;
}
}
while(!gata);
}
int main()
{
int n,i,max1=0,max2=0,k,ls,p;
interval x[100];
fin>>n;
for(i=1;i<=n;i++) citire(x[i]);
ordonarea(n,x);
k=1;
ls=x[1].b;
i=2;
while(i<=n)
{ if(x[i].a<=ls)
{
k++;
if(x[i].b<ls) ls=x[i].b;
}
else
{
if(k>max1) max1=k;
k=1;
p=i;
while(x[i-1].b>=x[p].a && i>=1) i--;
ls=x[i].b;
}
i++;
}
if(k>max1) max1=k;
fout<<max1;
fout<<endl;
ordonareb(n,x);
max2=1;
afisare(x[1]);
ls=x[1].b;
for(i=2;i<=n;i++)
if(x[i].a>ls)
{ max2++;
afisare(x[i]);
ls=x[i].b;
}
fout<<max2;
fin.close();
fout.close();
return 0;
}
|