Game of Two Stacks | HackerRank


`#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
ll t;
cin>>t;
for(ll i=0;i<t;i++)
{
ll n,m,k,l,o,p;
cin>>n>>m>>k;
ll a[n+1],b[m+1];
a[0]=0,b[0]=0;
for(ll i=1;i<=n;i++)
{
ll x,y;
cin>>x;
a[i]=x+a[i-1];
}
for(ll i=1;i<=m;i++)
{
ll x,y;
cin>>x;
b[i]=x+b[i-1];
}
o=1;
p=m;
while((o<=n)&&(p<=m)){
if(a[o]+b[p]>k){
p–;
if(p==0){
p=m;
o++;
}
}else{
break;
}
}
cout<<o+p<<"\n";
}

}`