QOJ.ac

QOJ

时间限制: 1 s 内存限制: 128 MB 总分: 100

#4906. Balls

统计

There are $n$ events, where each event $(t_i, x_i)$ indicates that a ball will land at position $x_i$ at time $t_i$.

Little F starts at $x_0 = 0$ at time $t_0 = 0$. Little F needs to catch all these balls, meaning that at each time $t_i$, either Little F or one of Little F's clones must be at position $x_i$.

If Little F is at position $x$ at the current time, they can move to $x-1$, $x$, or $x+1$ at the next time step.

Little F can place an immobile clone at their current position at any time. This clone can be used to catch a ball. However, when a new clone is placed, any previously existing clone will disappear after $0.01$ time units.

Determine if Little F can catch all the balls. If they can, output YES; otherwise, output NO.

Input

The first line contains a positive integer $n$.

The next $n$ lines each contain two numbers, where the $(i+1)$-th line represents $t_i$ and $x_i$.

Output

Output a single string, YES or NO, representing the answer.

Examples

Input 1

5
2 1
3 2 
9 6
10 5
13 0

Output 1

YES

Input 2

5
30 10
40 -10
51 9
52 8
53 20

Output 2

YES

Input 3

6
2 1
3 1
5 5
6 1
8 7
8 6

Output 3

YES

Input 4

10
1 -1
2 -1
3 1
4 2
4 -1
5 3
7 2
8 3
10 -2
11 1

Output 4

NO

Input 5

3
2 2
5 5
6 1

Output 5

YES

Constraints

There are 8 subtasks.

Subtask 1 ($5\%$): $n \le 20$, special properties.

Subtask 2 ($5\%$): $n \le 100$, depends on Subtask 1, special properties.

Subtask 3 ($10\%$): $n \le 5000$, depends on Subtask 2, special properties.

Subtask 4 ($20\%$): $n \le 5000$.

Subtask 5 ($20\%$): $n \le 10^5$, depends on Subtask 3, special properties.

Subtask 6 ($10\%$): $n \le 3 \times 10^5$, depends on Subtask 5, special properties.

Subtask 7 ($20\%$): $n \le 3 \times 10^5$, depends on Subtasks 4 and 6.

Subtask 8 ($10\%$): $n \le 10^6$, depends on Subtask 7.

For all data, $n \le 10^6$, $\forall i > 1, t_i \ge t_{i-1}$, and $\forall 1 \le i \le n, |x_i| \le 10^9, 0 \le t_i \le 10^9$.

Special properties: All $x_i$ are distinct.

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
EditorialOpen Official EditorialQingyu- Download

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.