CF1008B.Turn the Rectangles
入门
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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).
一行中有 n 个矩形。对于每个矩形,你可以选择将其旋转 90∘,也可以保持其原样不变。若将某个矩形旋转,则其宽变为高、高变为宽。注意:你可以旋转任意数量的矩形(包括全部或一个都不旋转),但不能改变矩形的顺序。
请判断是否存在一种旋转方案,使得所有矩形的高度按非升序排列。换言之,在完成所有旋转操作后,每个矩形的高度均不大于其前一个矩形的高度(如果存在前一个矩形)。
输入格式
The first line contains a single integer n (1≤n≤105) — the number of rectangles.
Each of the next n lines contains two integers wi and hi (1≤wi,hi≤109) — the width and the height of the i-th rectangle.
第一行包含一个整数 n(1≤n≤105)—— 矩形的数量。
接下来的 n 行中,每行包含两个整数 wi 和 hi(1≤wi,hi≤109)—— 第 i 个矩形的宽度和高度。
输出格式
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).
如果存在一种方式使矩形按高度非升序排列,则输出 "YES"(不带引号),否则输出 "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.
在第一个测试用例中,你可以旋转第二个和第三个矩形,使得它们的高度分别为 [4, 4, 3]。
在第二个测试用例中,不存在一种方式使得第二个矩形的高度不超过第一个矩形的高度。
输入解题思路,AI测评打分。不知道怎么写?