PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GD0000145. Xoay các hình chữ nhật (Turn the Rectangles)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Xoay các hình chữ nhật (Turn the Rectangles)
Turn the Rectangles
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
There are rectangles arranged in a fixed order. Each rectangle may be kept unchanged or rotated by , exchanging its width and height.
Determine whether their selected heights can be non-increasing from the first rectangle to the last.
Input
The first line contains . The next lines contain , the width and height of each rectangle.
Output
Print YES if a non-increasing sequence of heights can be obtained, otherwise print NO.
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; .
- Subtask 3 (50 points): ; .
Examples
Input
3
3 4
4 6
3 5
Output
YES
Explanation
Choosing heights is possible by rotating the second and third rectangles. Since , the answer is YES.