#include<bits/stdc++.h>
using namespace std;
int main() {
long long int t;
cin>>t;
while(t--){
long long int n,m;
cin>>n>>m;
long long int a[n];
long long int b[m];
for(int i=0;i<n;i++){
cin>>a[i];
}
for(int i=0;i<m;i++){
cin>>b[i];
}
long long int i=0;
long long int j=0;
long long int sum1=0,sum2=0;
long long int result=0;
while(i<n && j<m){
if(a[i]<b[j]){
sum1+=a[i++];
}
else if(a[i]>b[j]){
sum2+=b[j++];
}
else{
result+=max(sum1,sum2)+a[i];
i++;
j++;
sum1=0;
sum2=0;
}
}
while(i<n){
sum1+=a[i++];
}
while(j<m){
sum2+=b[j++];
}
int mod =1e9+7 ;
result+=max(sum1,sum2);
cout<<result%mod;
}
return 0;
}
Aint passing any tc
Hi @darkthunderassassin_818a6616c3c74f13,
print output for each test case in a new line
cout<<result%mod;
cout<<endl;
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.