Codeforces Round #497 (Div. 2)B. Turn the Rectangles
http://codeforces.com/contest/1008/problems
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MAXN=1e5+10;
const int INF=0x3f3f3f3f;
struct REC
{
int w,h;
}rec[MAXN];
int n;
int main()
{
//cout << "Hello world!" << endl;
cin>>n;
rec[0].h=INF;
bool flag=true;
for(int i=1;i<=n;i++)
{
cin>>rec[i].w>>rec[i].h;
if(max(rec[i].w,rec[i].h)<=rec[i-1].h)
rec[i].h=max(rec[i].w,rec[i].h);
else if(min(rec[i].w,rec[i].h)<=rec[i-1].h)
rec[i].h=min(rec[i].w,rec[i].h);
else if(min(rec[i].w,rec[i].h)>rec[i-1].h)
flag=false;
}
if(flag)
cout<<"YES"<<endl;
else cout<<"NO"<<endl;
return 0;
}