A11927 | Turn the Rectangles
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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).
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 $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.
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.
输出格式
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).
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.
In the second test, there is no way the second rectangle will be not higher than the first one.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted