Result: Accepted
Time: 8ms
Memory: 1120kB
#include<stdio.h>
#include<math.h>
int main(){
int n,i,j,sum = 1;
int h[1001],k[1001];
int hm[1001],km[1001];
scanf("%d",&n);
for(i = 0;i<n;i++){
scanf("%d %d",&h[i],&k[i]);
}
hm[0] = h[0];km[0] = k[0];
for(i = 1;i<n;i++){
for(j = 0;j<=sum-1;j++){
if((h[i]<=hm[j] && k[i] <=km[j]) || (h[i]<=km[j] && k[i] <= hm[j])){
hm[j] = h[i];
km[j] = k[i];
break;
}else if(j == sum-1){
sum++;
hm[sum-1] = h[i];
km[sum-1] = k[i];
break;
}
}
}
printf("%d\n",sum);
return 0;
}