Codeforces Round 497 (Div. 2)
B
Turn the Rectangles
Codeforces
1000
原题
← AC →
翻译中…

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. 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).

翻译中…

Input

翻译中…

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

翻译中…

Each of the next $n$ lines contains two integers $w_i$ and $h_i$ ($1 \leq w_i, h_i \leq 10^9$) — the width and the height of the $i$-th rectangle.

翻译中…

Output

翻译中…

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).

翻译中…

Note

翻译中…

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.

翻译中…

样例

Input #1
3
3 4
4 6
3 5
Output #1
YES
InputCopy OutputCopy
Input #2
2
3 4
5 5
Output #2
NO
InputCopy OutputCopy
题目信息
题号
1008B
时间限制
2 s
内存限制
256 MB
标签
贪心
排序

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。