CF1764E.Doremy's Number Line
普及/提高-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Doremy has two arrays a and b of n integers each, and an integer k.
Initially, she has a number line where no integers are colored. She chooses a permutation p of [1,2,…,n] then performs n moves. On the i-th move she does the following:
- Pick an uncolored integer x on the number line such that either:
- x≤api; or
- there exists a colored integer y such that y≤api and x≤y+bpi.
- Color integer x with color pi.
Determine if the integer k can be colored with color 1.
Doremy 有两个长度为 n 的整数数组 a 和 b,以及一个整数 k。
初始时,她有一条数轴,其上没有任何整数被染色。她选择 [1,2,…,n] 的一个排列 p,然后执行 n 次操作。在第 i 次操作中,她执行以下步骤:
- 在数轴上选取一个未被染色的整数 x,满足以下条件之一:
- x≤api;或者
- 存在一个已被染色的整数 y,使得 y≤api 且 x≤y+bpi。
- 将整数 x 染上颜色 pi。
请判断:整数 k 是否可以被染上颜色 1。
输入格式
The input consists of multiple test cases. The first line contains a single integer t (1≤t≤104) — the number of test cases. The description of the test cases follows.
The first line contains two integers n and k (1≤n≤105, 1≤k≤109).
Each of the following n lines contains two integers ai and bi (1≤ai,bi≤109).
It is guaranteed that the sum of n over all test cases does not exceed 105.
输入包含多个测试用例。第一行包含一个整数 t(1≤t≤104),表示测试用例的数量。随后是各测试用例的描述。
每个测试用例的第一行包含两个整数 n 和 k(1≤n≤105,1≤k≤109)。
接下来的 n 行中,每行包含两个整数 ai 和 bi(1≤ai,bi≤109)。
保证所有测试用例的 n 值之和不超过 105。
输出格式
For each test case, output "YES" (without quotes) if the point k can be colored with color 1. 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).
对于每个测试用例,如果点 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
说明/提示
For the first test case, it is impossible to color point 16 with color 1.
For the second test case, p=[2,1,3,4] is one possible choice, the detail is shown below.
- On the first move, pick x=8 and color it with color 2 since x=8 is uncolored and x≤a2.
- On the second move, pick x=16 and color it with color 1 since there exists a colored point y=8 such that y≤a1 and x≤y+b1.
- On the third move, pick x=0 and color it with color 3 since x=0 is uncolored and x≤a3.
- On the forth move, pick x=−2 and color it with color 4 since x=−2 is uncolored and x≤a4.
- In the end, point −2,0,8,16 are colored with color 4,3,2,1, respectively.
For the third test case, p=[2,1,4,3] is one possible choice.
For the fourth test case, p=[2,3,4,1] is one possible choice.
对于第一个测试用例,无法将点 16 染成颜色 1。
对于第二个测试用例,p=[2,1,3,4] 是一种可行的选择,具体过程如下所示。
- 第一步:选择 x=8,并用颜色 2 对其染色,因为 x=8 尚未染色,且满足 x≤a2。
- 第二步:选择 x=16,并用颜色 1 对其染色,因为存在一个已被染色的点 y=8,使得 y≤a1 且 x≤y+b1。
- 第三步:选择 x=0,并用颜色 3 对其染色,因为 x=0 尚未染色,且满足 x≤a3。
- 第四步:选择 x=−2,并用颜色 4 对其染色,因为 x=−2 尚未染色,且满足 x≤a4。
- 最终,点 −2,0,8,16 分别被染成颜色 4,3,2,1。
对于第三个测试用例,p=[2,1,4,3] 是一种可行的选择。
对于第四个测试用例,p=[2,3,4,1] 是一种可行的选择。
输入解题思路,AI测评打分。不知道怎么写?