Cake Assembly Line

Cake Assembly Line
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 [aiw,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 [bih,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.
Input

Each test contains multiple test cases. The first line contains the number of test cases t (1t1051≤≤105). The description of the test cases follows.

The first line of each test case contains three integers nw, and hℎ (1n1051≤≤105; 1w,h1051≤,ℎ≤105; hwℎ≤) — 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 a11, a22, ..., an (1ai1091≤≤109) — the positions of the cakes centers. It is guaranteed that ai+w<ai+1w+<+1− for all i.

The third line contains n integers b11, b22, ..., bn (1bi1091≤≤109) — the positions of the dispensers. It is guaranteed that bi+h<bi+1h+ℎ<+1−ℎ for all i.

It is guaranteed that the sum of n over all test cases does not exceed 105105.

Output

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.

Example
input
Copy
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
output
Copy
YES YES NO YES
Note

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,244,9,14,19,24.

In the third example, we can't move the conveyor accordingly.

复制代码
//设向右为正方向 //蛋糕如果需要移动到最右端点,那就是rb-ra //最左端点的话就是lb-la //蛋糕只需要向右移动{l,r}这个区间就是合法的 //对于每个蛋糕都有一个这样的区间,只需要判断每个区间是否都有交集就可以了 #include <bits/stdc++.h> //#define int long long using namespace std; const int N=1e5+10,mod=1e9+7; string s; long long n,t,a[N],b[N],res,num,ans,w,h,l=-1e9,r=1e9; bool vis[N]; int main() { std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0); cin>>t; while(t--){ cin>>n>>w>>h; l=-1e9,r=1e9; for(int i=0;i<n;i++) cin>>a[i]; for(int i=0;i<n;i++) cin>>b[i]; for(int i=0;i<n;i++){ l=max(l,b[i]+h-a[i]-w),r=min(r,b[i]-h-a[i]+w);//判断是否有交集 if(l>r){ cout<<"NO"<<endl; goto nexts; } } cout<<"YES"<<endl; nexts:; } return 0; }
复制代码

 


__EOF__

本文作者Sakurajimamai
本文链接https://www.cnblogs.com/o-Sakurajimamai-o/p/17513875.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角推荐一下。您的鼓励是博主的最大动力!
posted @   o-Sakurajimamai-o  阅读(18)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
-- --
点击右上角即可分享
微信分享提示