# Runtime Error:Dessert Wizard

i don’t know why this code is giving runtime error.
http://www.codechef.com/viewsolution/6992337
Or else the code is here:
#include

using namespace std;
long long int rdp[10005],ldp[10005];
int main()
{
int t;
long int n,i;
long long int a[1000];
cin>>t;
while(t–)
{
long long int sum=0,max1=0,max2=0;
cin>>n;
for(i=1;i<=n;i++)
{
cin>>a[i];
sum+=a[i];
}
//cout<<“sum=”<<sum<<endl;
ldp[0]=sum;
for(i=1;i<=n;i++)
{
ldp[i]=ldp[i-1]-2a[i];
if(ldp[i]>max1)
max1=ldp[i];
}
//for(i=1;i<=n;i++)
//cout<<ldp[i]<<"\t";
//cout<<“max1=”<<max1<<endl;
rdp[n+1]=sum;
for(i=n;i>=1;i–)
{
rdp[i]=rdp[i+1]-2
a[i];
//cout<<rdp[i+1]<<"\t"<<2*a[i]<<endl;
if(rdp[i]>max2)
max2=rdp[i];
}
//for(i=1;i<=n+1;i++)
//cout<<rdp[i]<<"\t";
//cout<<“max2=”<<max2<<endl;
cout<<max(max1,max2)<<endl;
}
}

At the first glance, I found a bug in your code. You declared the array a to be of size 1000, but in the problem statement the upper limit of n is 10000. [ I think it’s a typo ]

yup!!
Thanks a lot.

But still the code is wrong.
Can you tell me the logical error??