Why am i getting run time exceeded error?

#include
#include
using namespace std;

void sum(int a[] , int m , int b[] , int n)
{

int carry=0;
int i=m ;
int j=n ;
int k=max(m,n);
int s[1001];

while(i>-1 && j>-1)
{
s[k]=(a[i]+b[j]+carry);
carry=s[k]/10;
s[k]%=10;
k–;
i–;
j–;
}

while(i>-1)
{
s[k]=a[i]+carry;
carry=0;
}

while(j>-1)
{
s[k]=b[j]+carry;
carry=0;
}

if(s[0]!=0)
{
cout<<s[0]<<", β€œ;
}
for(i=1 ; i<max(m,n) ; i++)
{
cout<<s[i]<<”, ";
}
cout<<β€œEND”;

}

int main() {
int a[1001] , b[1001],m,n;
cin>>m;

for(int i=1 ; i<m+1 ; i++)
{
cin>>a[i];
}

cin>>n;

for(int i=1 ; i<n+1 ; i++)
{
cin>>b[i];
}

sum(a,m,b,n);

return 0;

}

Hey,you have intialised elements from 1 to n so you can’t access index 0.In your code you have written i>-1 and j>-1 so it will try to access 0th index ,when either i==0 or j==0 so it is giving run time error.
Change it to i>0 and j>0

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.