Result: Accepted
Time: 5ms
Memory: 1120kB
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<ctype.h>
using namespace std;
int main()
{
int n,h,w,i,sum,h1,w1,p;
scanf("%d",&n);
scanf("%d %d",&h,&w);
int a[1002][2];
a[1][0]=h;
a[1][1]=w;
sum=0;
p=1;
for(i=2;i<=n;i++)
{
int f=0;
scanf("%d %d",&h1,&w1);
for(int j=1;j<=p;j++)
{
if((h1<=a[j][0]&&w1<=a[j][1])||(h1<=a[j][1]&&w1<=a[j][0]))
{
p=p;
a[j][0]=h1;
a[j][1]=w1;
f=1;
break;
}
}
if(f==0)
{
p+=1;
a[p][0]=h1;
a[p][1]=w1;
}
}
printf("%d\n",p);
}