Result: Accepted
Time: 4ms
Memory: 1120kB
#include<stdio.h>
int main() {
int n,i,t,p;
int x=1;
scanf("%d",&n);
int h[n],w[n];
int h1[n],w1[n];
scanf("%d%d",&h[0],&w[0]);
h1[0]=h[0];
w1[0]=w[0];
for(i=1; i<n; ++i) {
scanf("%d%d",&h[i],&w[i]);
if(h[i]<=h1[0]&&w[i]<=w1[0]) {
h1[0]=h[i];
w1[0]=w[i];
continue;
} else if(h[i]<=w1[0]&&w[i]<=h1[0]) {
h1[0]=w[i];
w1[0]=h[i];
continue;
} else {
int p=0;
for(t=0; t<x; ++t) {
if(h[i]<=h1[t]&&w[i]<=w1[t]) {
h1[t]=h[i];
w1[t]=w[i];
p=1;
break;
} else if(h[i]<=w1[t]&&w[i]<=h1[t]) {
h1[t]=w[i];
w1[t]=h[i];
p=1;
break;
}
}
if(p==0) {
h1[x]=h[i];
w1[x]=w[i];
++x;
}
}
}
printf("%d",x);
return 0;
}