91 solutions

  • 0
    @ 2026-2-13 15:11:03
    #include<bits/stdc++.h>
    using namespace std;
    const int N=2e5+10;
    long long a[N],b[N];
    long long f[N][2];
    int main()
    {
    	long long n,k;
    	cin>>n>>k;
    	for(int i=1;i<=n;i++) cin>>a[i];
    	for(int i=1;i<=n;i++) cin>>b[i];
    	f[1][0]=f[1][1]=1;
    	for(int i=2;i<=n;i++)
    	{
    		if(f[i-1][0])
    		{
    			if(abs(a[i-1]-a[i])<=k)
    			{
    				f[i][0]=true;
    			}
    			if(abs(a[i-1]-b[i])<=k)
    			{
    				f[i][1]=true; 
    			}
    		}
    		if(f[i-1][1])
    		{
    			if(abs(b[i-1]-a[i])<=k)
    			{
    				f[i][0]=true;
    			}
    			if(abs(b[i-1]-b[i])<=k)
    			{
    				f[i][1]=true;
    		 	} 
    		}
    	}
    	if(f[n][1]||f[n][0]) cout<<"Yes"<<endl;
    	else cout<<"No"<<endl;
    	return 0;
    }
    
    

    Information

    ID
    838
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    1
    Tags
    # Submissions
    799
    Accepted
    143
    Uploaded By