| 7 | using namespace std; |
| 8 | |
| 9 | int main() { |
| 10 | int n; |
| 11 | cin>>n; |
| 12 | int a[n][2]; |
| 13 | int s[n]; |
| 14 | int flag=0; |
| 15 | for(int i=0;i<n;i++) |
| 16 | cin>>a[i][0]>>a[i][1]; //Taking Inputs |
| 17 | s[0]=max(a[0][0],a[0][1]); //We want a greedy approach. Thus, we use the greatest dimension of the first rectangle. |
| 18 | for(int i=1;i<n;i++) |
| 19 | { |
| 20 | if(max(a[i][0],a[i][1])<=s[i-1]) s[i]=max(a[i][0],a[i][1]); //Then we check if either of the two dimensions are smaller than the previous height. |
| 21 | else if(min(a[i][0],a[i][1])<=s[i-1]) s[i]=min(a[i][0],a[i][1]); //IF both are smaller we choose the larger of the two smaller. |
| 22 | else |
| 23 | { |
| 24 | flag=1; |
| 25 | break; //If none are smaller we dont need to loop further, we can break here. |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | if(flag==0) cout<<"YES"<<endl; |
| 30 | else cout<<"NO"<<endl; |
| 31 | |
| 32 | return 0; |
| 33 | } |