QOJ.ac

QOJ

시간 제한: 2.0 s 메모리 제한: 256 MB 총점: 100 해킹 가능 ✓

#17655. 哆来咪的数轴

통계

Doremy 有两个长度为 $n$ 的整数数组 $a$ 和 $b$,以及一个整数 $k$。

起初,她有一条数轴,数轴上所有的整数都没有被染色。她选择 $[1, 2, \dots, n]$ 的一个排列 $p$,然后进行 $n$ 次操作。在第 $i$ 次操作中,她会执行以下步骤:

  • 在数轴上选择一个未染色的整数 $x$,使得满足以下条件之一:

    • $x \le a_{p_i}$;或
    • 存在一个已被染色的整数 $y$,满足 $y \le a_{p_i}$ 且 $x \le y + b_{p_i}$。
  • 将整数 $x$ 染成颜色 $p_i$。

请判断整数 $k$ 是否能被染成颜色 1。

输入格式

输入包含多组测试数据。第一行包含一个整数 $t$ ($1 \le t \le 10^4$) — 测试数据的组数。接下来是每组测试数据的描述。

每组测试数据的第一行包含两个整数 $n$ 和 $k$ ($1 \le n \le 10^5$, $1 \le k \le 10^9$)。

接下来的 $n$ 行,每行包含两个整数 $a_i$ 和 $b_i$ ($1 \le a_i, b_i \le 10^9$)。

保证所有测试数据的 $n$ 之和不超过 $10^5$。

输出格式

对于每组测试数据,如果点 $k$ 可以被染成颜色 1,则输出 "YES"(不含双引号)。否则,输出 "NO"(不含双引号)。

你可以输出 "YES" 和 "NO" 的任意大小写形式(例如,字符串 "yEs"、"yes" 和 "Yes" 都会被视为肯定的回答)。

样例

输入样例 1

6
4 16
5 3
8 12
10 7
15 1
4 16
8 12
10 7
15 1
5 3
4 16
10 7
15 1
5 3
8 12
4 16
15 1
5 3
8 12
10 7
1 1000000000
500000000 500000000
2 1000000000
1 999999999
1 1

输出样例 1

NO
YES
YES
YES
NO
YES

说明

对于第一组测试数据,无法将点 16 染成颜色 1。

对于第二组测试数据,$p = [2, 1, 3, 4]$ 是一种可能的选择,具体步骤如下:

  • 在第一次操作中,选择 $x = 8$ 并将其染成颜色 2,因为 $x = 8$ 未染色且 $x \le a_2$。
  • 在第二次操作中,选择 $x = 16$ 并将其染成颜色 1,因为存在一个已被染色的点 $y = 8$ 满足 $y \le a_1$ 且 $x \le y + b_1$。
  • 在第三次操作中,选择 $x = 0$ 并将其染成颜色 3,因为 $x = 0$ 未染色且 $x \le a_3$。
  • 在第四次操作中,选择 $x = -2$ 并将其染成颜色 4,因为 $x = -2$ 未染色且 $x \le a_4$。
  • 最终,点 $-2, 0, 8, 16$ 分别被染成了颜色 $4, 3, 2, 1$。

对于第三组测试数据,$p = [2, 1, 4, 3]$ 是一种可能的选择。

对于第四组测试数据,$p = [2, 3, 4, 1]$ 是一种可能的选择。

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.