# Wrong answer error was showing --may lunch time -wierd walk

#include<bits/stdc++.h>
using namespace std;
#include
#include
#include
#include
#include

int main()
{
int T;
cin>>T;
while(T–)
{
long long N,X;
cin>>N;

long long A[N],B[N];

``````for(X=0;X<N;X++)
{
cin>>A[X];

}
for(X=0;X<N;X++)
{
cin>>B[X];

}

long long w=0;
for(X=0;X<N;X++)
{
if(A[X]==B[X])
{
w=w+((A[X]+B[X])/2);
}

}
cout<<w<<endl;
``````

}

}

Here the distance travelled should also be equal till the A[i]==B[i]
Here is my approach

#include<bits/stdc++.h>
using namespace std;
#define lli long long int
lli A[100001],B[100001],pre1[100001],pre2[100001];
lli WWALK(lli A[],lli B[],lli n){
lli i,sum=0;
pre1[0]=pre2[0]=0;
for(int i=1;i<=n;i++){
pre1[i]=A[i]+pre1[i-1];

``````	pre2[i]=B[i]+pre2[i-1];

if(pre1[i]==pre2[i] && A[i]==B[i]){
sum+=A[i];
}
}
return sum;
``````

}
int main(){
int t;
lli n;
cin>>t;
while(t–){
cin>>n;
for(lli i=1;i<=n;i++)
cin>>A[i];

``````	for(lli i=1;i<=n;i++)
cin>>B[i];

cout<<WWALK(A,B,n)<<endl;
}
return 0;
``````

}

1 Like

thank you

1 Like

Yes, You should also check if the distance travelled by Bob and Alice is equal or not.
Here is my code in C,

#include <stdio.h>
int main(){
int testcases;
scanf("%d\n", &testcases);
while(testcases–){
long long int n,dalice=0,dbob=0,i,j=0,sum=0;
scanf("%lld\n", &n);
long long int alice[n];
long long int bob[n];
for(long long int x=0;x<n;x++){
scanf("%lld", &alice[x]);
}

``````    for(long long int z=0;z<n;z++){
scanf("%lld", &bob[z]);
}

for(i=0;i<n;i++){
dalice = alice[i] + dalice;
dbob = bob[i] + dbob;
if(dalice==dbob && alice[i]==bob[i]){
sum = sum + alice[i];
}
}

printf("%lld\n", sum);

}
``````

}

1 Like