My code is below and it is giving runtime error.I have tried every test cases given in threads and my code seems to be fine with it . kindly help
include
include
include
using namespace std;
define ll long long
ll arr[200001];
void ini(ll x)
{
ll sum[x+1];
sum[0]=0;
ll i;
ll a;
for(i=1;i<x+1;i++)
{
cin >> a;
sum[i]=a;
arr[sum[i]+10000]=i;
sum[i]+=sum[i-1];
}
ll y,z,z1=0;
cin >> y;
ll s=0,s1=0;
for(i=0;i<y;i++)
{
cin >>z;
s+=z;
if(arr[z+10000])
{
if(sum[(arr[z+10000])]-z1>=s)
{
s1+=sum[(arr[z+10000])]-z1;
}
else
{
s1+=s;
}
s=0;
z1=sum[(arr[z+10000])];
}
}
if(sum[x]-z1>=s)
{
s1+=sum[x]-z1;
}
else
{
s1+=s;
}
cout << s1 << endl;
}
int main()
{
memset(arr,0,200001);
ll x;
while(1)
{
cin >> x;
if(!x)
{
break;
}
ini(x);
}
}