Result: Accepted
Time: 7ms
Memory: 1764kB
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct book
{
int h,w;
}sz[1005];
int main()
{
int n;int sum=0;
cin>>n;
for(int i=1;i<=n;i++)
{
int a,b;
scanf("%d%d",&a,&b);
int flag=0;
for(int i=1;i<=sum;i++)
{
if(sz[i].h>=a&&sz[i].w>=b)
{
sz[i].h=a;
sz[i].w=b;
flag=1;
break;
}
else if(sz[i].w>=a&&sz[i].h>=b)
{
sz[i].h=b;
sz[i].w=a;
flag=1;
break;
}
}
if(!flag)
{
sum++;
sz[sum].h=a;
sz[sum].w=b;
}
}
cout<<sum;
return 0;
}