← 返回题目列表

Codeforces · 1008/B

B. 转动矩形

中文机器翻译题面 查看原题

There are $$$n$$$ rectangles in a row. You can either turn each rectangle by $$$90$$$ 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.换句话说,在所有转弯之后,每个矩形的高度必须不大于前一个矩形的高度(如果是这样的话)。

输入

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

接下来的 $$$n$$$ 行包含两个整数 $$$w_i$$$ 和 $$$h_i$$$ ($$$1 \leq w_i, h_i \leq 10^9$$$) — 第 $$$i$$$ 个矩形的宽度和高度。

输出

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

您可以以任何大小写(大写或小写)打印每个字母。

示例

输入 #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.