CF1008B.Turn the Rectangles

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

There are nn rectangles in a row. You can either turn each rectangle by 9090 degrees or leave it as it is. If you turn a rectangle, its width will be height, and its height will be width. Notice that you can turn any number of rectangles, you also can turn all or none of them. You can not change the order of the rectangles.

Find out if there is a way to make the rectangles go in order of non-ascending height. In other words, after all the turns, a height of every rectangle has to be not greater than the height of the previous rectangle (if it is such).

输入格式

The first line contains a single integer nn ( 1n1051 \leq n \leq 10^5 ) — the number of rectangles.

Each of the next nn lines contains two integers wiw_i and hih_i ( 1wi,hi1091 \leq w_i, h_i \leq 10^9 ) — the width and the height of the ii -th rectangle.

输出格式

Print "YES" (without quotes) if there is a way to make the rectangles go in order of non-ascending height, otherwise print "NO".

You can print each letter in any case (upper or lower).

输入输出样例

  • 输入#1

    3
    3 4
    4 6
    3 5
    

    输出#1

    YES
    
  • 输入#2

    2
    3 4
    5 5
    

    输出#2

    NO
    

说明/提示

In the first test, you can rotate the second and the third rectangles so that the heights will be [4, 4, 3].

In the second test, there is no way the second rectangle will be not higher than the first one.

首页