Result: Accepted
Time: 3ms
Memory: 1128kB
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
//int h[1001], w[1001];
//int h1[1001], w1[1001];
int a[1001], b[1001];
int main(){
int n;
scanf("%d", &n);
int h, w, h1, w1;
int i;
int num = 1;
for(i = 0; i< n; i++){
scanf("%d %d", &h, &w);
if(i==0){
a[1] = h;
b[1] = w;
} else{
int t;
for(t = 1; t <= num ; t++){
if(h <= a[t]&& w<= b[t]){
a[t] = h;
b[t] = w;
break;
} else if(h <= b[t]&& w <= a[t]){
a[t] = w;
b[t] = h;
break;
} else {
if(t==num){
num++;
a[num] = h;
b[num] = w;
break;
}
}
}
}
}
printf("%d", num);
return 0;
}