CF1786B.Cake Assembly Line
普及-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
A cake assembly line in a bakery was once again optimized, and now n cakes are made at a time! In the last step, each of the n cakes should be covered with chocolate.
Consider a side view on the conveyor belt, let it be a number line. The i-th cake occupies the segment [ai−w,ai+w] on this line, each pair of these segments does not have common points. Above the conveyor, there are n dispensers, and when a common button is pressed, chocolate from the i-th dispenser will cover the conveyor segment [bi−h,bi+h]. Each pair of these segments also does not have common points.
Cakes and dispensers corresponding to the first example.
The calibration of this conveyor belt part has not yet been performed, so you are to make it. Determine if it's possible to shift the conveyor so that each cake has some chocolate on it, and there is no chocolate outside the cakes. You can assume that the conveyour is long enough, so the cakes never fall. Also note that the button can only be pressed once.
In the first example we can shift the cakes as shown in the picture.
一家面包店的蛋糕装配线再次经过优化,现在每次可同时制作 n 个蛋糕!在最后一步中,这 n 个蛋糕中的每一个都需覆盖上巧克力。
考虑传送带的侧视图,将其建模为一条数轴。第 i 个蛋糕在该数轴上占据区间 [ai−w,ai+w],且这些区间两两互不相交。传送带正上方安装有 n 个巧克力分配器;当按下统一按钮时,第 i 个分配器喷出的巧克力将覆盖传送带上的区间 [bi−h,bi+h],且这些区间也两两互不相交。
与第一个样例对应的蛋糕和分配器。
该传送带部分尚未完成校准,因此需要你来完成。请判断:是否存在一种对传送带的平移方式(即整体移动所有蛋糕),使得每个蛋糕上均被覆盖有巧克力,且巧克力完全不落在蛋糕之外?你可以假设传送带足够长,蛋糕不会掉落。另外请注意:按钮仅能按压一次。
在第一个样例中,我们可以按图示方式平移蛋糕。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤105). The description of the test cases follows.
The first line of each test case contains three integers n, w, and h (1≤n≤105; 1≤w,h≤105; h≤w) — the number of cakes and dispensers, as well as the halfwidths of cakes and segments on which the chocolate is dispensed.
The second line contains n integers a1, a2, ..., an (1≤ai≤109) — the positions of the cakes centers. It is guaranteed that ai+w<ai+1−w for all i.
The third line contains n integers b1, b2, ..., bn (1≤bi≤109) — the positions of the dispensers. It is guaranteed that bi+h<bi+1−h for all i.
It is guaranteed that the sum of n over all test cases does not exceed 105.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤105)。随后是各测试用例的描述。
每个测试用例的第一行包含三个整数 n、w 和 h(1≤n≤105;1≤w,h≤105;h≤w)——分别表示蛋糕数量、分配器数量,以及蛋糕的半宽和巧克力分配区段的半宽。
每个测试用例的第二行包含 n 个整数 a1、a2、…、an(1≤ai≤109)——表示各蛋糕中心的位置。保证对所有 i 均满足 ai+w<ai+1−w。
每个测试用例的第三行包含 n 个整数 b1、b2、…、bn(1≤bi≤109)——表示各分配器的位置。保证对所有 i 均满足 bi+h<bi+1−h。
保证所有测试用例中 n 的总和不超过 105。
输出格式
For each test case output "YES", if it's possible to shift the conveyor in such a way that each cake ends up with some chocolate, and no chocolate is outside the cakes, and "NO" otherwise.
You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.
对于每个测试用例,如果能够以某种方式平移传送带,使得每块蛋糕上都恰好覆盖有巧克力,且巧克力不会超出任何蛋糕的范围,则输出 “YES”;否则输出 “NO”。
你可以以任意大小写形式输出答案(大写或小写均可)。例如,字符串 “yEs”、“yes”、“Yes” 和 “YES” 均会被识别为肯定回答。
输入输出样例
输入#1
4 3 10 5 65 95 165 40 65 145 5 2 1 1 6 11 16 21 4 9 14 19 24 3 3 2 13 22 29 5 16 25 4 4 1 27 36 127 136 35 50 141 144
输出#1
YES YES NO YES
说明/提示
The first example is shown in the figures in the statement.
In the second example, we can move the conveyor, for example, so that the centers of the cakes are at 4,9,14,19,24.
In the third example, we can't move the conveyor accordingly.
第一个示例如题面中的图所示。
在第二个示例中,我们可以移动传送带,例如使蛋糕中心的位置分别为 4,9,14,19,24。
在第三个示例中,我们无法相应地移动传送带。
输入解题思路,AI测评打分。不知道怎么写?