Result: Accepted
Time: 3ms
Memory: 1764kB
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
const int inf =0x3f3f3f3f;
using namespace std;
int cnt=1;
int maxn[1001],minn[1001];
int check(int a,int b)
{
for(int i=1;i<=cnt;++i)
{
if(a<=maxn[i]&&b<=minn[i])
return i;
}
return 0;
}
int main()
{
int n;
cin>>n;
int a,b;
cin>>a>>b;
if(b>=a) swap(a,b);
maxn[1]=a,minn[1]=b;
for(int i=1;i<n;++i)
{
cin>>a>>b;
if(b>=a) swap(a,b);
if(check(a,b))
{
int temp=check(a,b);
maxn[temp]=a,minn[temp]=b;
}
else
{
cnt++;
maxn[cnt]=a,minn[cnt]=b;
}
}
cout<<cnt;
}