SUBSTADD(why my code is wrong)

PROBLEM LINK :Contest Page | CodeChef
#include <bits/stdc++.h>

using namespace std;

int main(){

int t;

cin>>t;

while(t–){

long long int n,x,y;

cin>>n;

cin>>x;

cin>>y;

int a[n];

int b[n];

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++){

if(a[i]+x==b[i]){

    a[i]=a[i]+x;

}

}

for(int i=0;i<n;i++){

if(a[i]+y==b[i]){

    a[i]=a[i]+y;

}

}

bool flag=0;

for(int i=0;i<n;i++){

    if(a[i]==b[i]){

        flag=true;

    }

    else{

        flag=false;

        break;

    }

}

if(flag==true){

    cout<<"Yes"<<endl;

}

else {

    cout<<"No"<<endl;

}

}

return 0;

}

Add a one more condition for which a[i] == b[i] and x and y are non zeroes.
Test Case: ```
1
3 2 5
9 5 1
11 5 3

Your code fails for this condition and prints YES whereas it is NO.

Thanks bro for giving such a nice explanation to me . It helped me a lot