WWALK - Editorial

First you should format your code or give link to your submission. Your mistake is that you are only checking if their speed is equal or not. There should be one more condition that they are at same position.
You may see this CodeChef: Practical coding for everyone

plz will u explain me your code

In array suma[] and sumb[] I have simply calculated the distance they have covered till ith second. So, now if for some time they have same value (suma[i] and sumb[i]) then this means that are at same position at this time. Now, if their speed is also equal then they will cover that distance together. Hope you understood.

3 Likes

Hi Sebastian, you can check my code for reference, I have applied a similar approach :slightly_smiling_face:

int main()
{
	zapp;
	ll t;
	cin>>t;
	while(t--)
	{
	    ll n,i;
	    cin>>n;
	    vector<ll> a(n),b(n);
	    for(i=0;i<n;i++)
	    	cin>>a[i];
	    for(i=0;i<n;i++)
	    	cin>>b[i];
	    ll suma = 0, sumb = 0,tog = 0;
	    for(i=0;i<n;i++)
	    {
	    	if(suma == sumb && a[i] == b[i])
	    		tog+=a[i];
			suma+=a[i];
			sumb+=b[i];
		}
		cout<<tog<<"\n";
	}
}
1 Like

Why was i getting WA for this approach , i have tried different cases as well , and all are coming right but still WA…? any suggestions…?

for _ in range(int(input())):
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
s_a = 0
s_b = 0
i_a = 0
i_b = 0
c=0

for i in range(len(A)):
    i_a = s_a
    i_b = s_b

    s_a = s_a + A[i]
    s_b = s_b + B[i]

    if s_a - i_a == s_b - i_b:
        c+= (s_a - i_a)
print(c)

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

int main() {
int t;
cin>>t;
while(t–){
long long n,sum=0,suma=0,sumb=0;
long long arr[n],brr[n];
for (int i=0;i<n;i++){
cin>>arr[i];
}
for(int i=0;i<n;i++){
cin>>brr[i];
}
for(int i=0;i<n;i++){
suma+=arr[i];
sumb+=brr[i];
if(suma==sumb){
if(arr[i]==brr[i]){
sum+=arr[i];
}
}
}
cout<<sum<<endl;

}
return 0;

}

can some one what is wrong with my ans.