Result: Accepted
Time: 4ms
Memory: 1120kB
#include<stdio.h>
#include<math.h>
#include<string.h>
int main(){
int n,h,w,i,sum,j,f;
int shuh[1001]={0};
int shuw[1001]={0};
scanf("%d",&n);
sum=0;
for(i=0;i<n;++i){
scanf("%d %d",&h,&w);
if(sum==0){
shuh[0]=h;
shuw[0]=w;
sum++;
}
f=0;
for(j=0;j<sum;++j){
if(h<=shuh[j]&&w<=shuw[j]){
shuh[j]=h;
shuw[j]=w;
f=1;
break;
}
else if(w<=shuh[j]&&h<=shuw[j]){
shuh[j]=w;
shuw[j]=h;
f=1;
break;
}
}
if(f!=1){
shuh[sum]=h;
shuw[sum]=w;
sum++;
}
}
printf("%d",sum);
return 0;
}