CF1764E.Doremy's Number Line

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Doremy has two arrays aa and bb of nn integers each, and an integer kk.

Initially, she has a number line where no integers are colored. She chooses a permutation pp of [1,2,,n][1,2,\ldots,n] then performs nn moves. On the ii-th move she does the following:

  • Pick an uncolored integer xx on the number line such that either:
    • xapix \leq a_{p_i}; or
    • there exists a colored integer yy such that yapiy \leq a_{p_i} and xy+bpix \leq y+b_{p_i}.
  • Color integer xx with color pip_i.

Determine if the integer kk can be colored with color 11.

Doremy 有两个长度为 nn 的整数数组 aabb,以及一个整数 kk

初始时,她有一条数轴,其上没有任何整数被染色。她选择 [1,2,,n][1,2,\ldots,n] 的一个排列 pp,然后执行 nn 次操作。在第 ii 次操作中,她执行以下步骤:

  • 在数轴上选取一个未被染色的整数 xx,满足以下条件之一:
    • xapix \leq a_{p_i};或者
    • 存在一个已被染色的整数 yy,使得 yapiy \leq a_{p_i}xy+bpix \leq y+b_{p_i}
  • 将整数 xx 染上颜色 pip_i

请判断:整数 kk 是否可以被染上颜色 11

输入格式

The input consists of multiple test cases. The first line contains a single integer tt (1t1041\le t\le 10^4) — the number of test cases. The description of the test cases follows.

The first line contains two integers nn and kk (1n1051 \le n \le 10^5, 1k1091 \le k \le 10^9).

Each of the following nn lines contains two integers aia_i and bib_i (1ai,bi1091 \le a_i,b_i \le 10^9).

It is guaranteed that the sum of nn over all test cases does not exceed 10510^5.

输入包含多个测试用例。第一行包含一个整数 tt1t1041\le t\le 10^4),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含两个整数 nnkk1n1051 \le n \le 10^51k1091 \le k \le 10^9)。

接下来的 nn 行中,每行包含两个整数 aia_ibib_i1ai,bi1091 \le a_i,b_i \le 10^9)。

保证所有测试用例的 nn 值之和不超过 10510^5

输出格式

For each test case, output "YES" (without quotes) if the point kk can be colored with color 11. Otherwise, output "NO" (without quotes).

You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).

对于每个测试用例,如果点 kk 可以被染成颜色 11,则输出 "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

说明/提示

For the first test case, it is impossible to color point 1616 with color 11.

For the second test case, p=[2,1,3,4]p=[2,1,3,4] is one possible choice, the detail is shown below.

  • On the first move, pick x=8x=8 and color it with color 22 since x=8x=8 is uncolored and xa2x \le a_2.
  • On the second move, pick x=16x=16 and color it with color 11 since there exists a colored point y=8y=8 such that ya1y\le a_1 and xy+b1x \le y + b_1.
  • On the third move, pick x=0x=0 and color it with color 33 since x=0x=0 is uncolored and xa3x \le a_3.
  • On the forth move, pick x=2x=-2 and color it with color 44 since x=2x=-2 is uncolored and xa4x \le a_4.
  • In the end, point 2,0,8,16-2,0,8,16 are colored with color 4,3,2,14,3,2,1, respectively.

For the third test case, p=[2,1,4,3]p=[2,1,4,3] is one possible choice.

For the fourth test case, p=[2,3,4,1]p=[2,3,4,1] is one possible choice.

对于第一个测试用例,无法将点 1616 染成颜色 11

对于第二个测试用例,p=[2,1,3,4]p=[2,1,3,4] 是一种可行的选择,具体过程如下所示。

  • 第一步:选择 x=8x=8,并用颜色 22 对其染色,因为 x=8x=8 尚未染色,且满足 xa2x \le a_2
  • 第二步:选择 x=16x=16,并用颜色 11 对其染色,因为存在一个已被染色的点 y=8y=8,使得 ya1y\le a_1xy+b1x \le y + b_1
  • 第三步:选择 x=0x=0,并用颜色 33 对其染色,因为 x=0x=0 尚未染色,且满足 xa3x \le a_3
  • 第四步:选择 x=2x=-2,并用颜色 44 对其染色,因为 x=2x=-2 尚未染色,且满足 xa4x \le a_4
  • 最终,点 2,0,8,16-2,0,8,16 分别被染成颜色 4,3,2,14,3,2,1

对于第三个测试用例,p=[2,1,4,3]p=[2,1,4,3] 是一种可行的选择。

对于第四个测试用例,p=[2,3,4,1]p=[2,3,4,1] 是一种可行的选择。

输入解题思路,AI测评打分。不知道怎么写?

首页