can u please tell me why it is giving wrong answer for reign?

//http://www.codechef.com/problems/CHODE

#include
#include<stdio.h>
using namespace std;

long long int max(long long int x,long long int y)
{ return (y > x)? y : x; }

long long int maxSubArraySum(long long int a[],long long int size,long long int k,long long int n)
{
long long int max_so_far =a[0];
long long int i,pos=0;
long long int curr_max =a[0];

long long int sum=0;
for (i=1; i < size; i++)
{
//curr_max = max(a*, curr_max+a*);
if(curr_max+a*>a*)
{
curr_max=curr_max+a*;
//pos=i;
}
else
{
curr_max=a*;
//pos=i;
}

    //max_so_far = max(max_so_far, curr_max);
    if(max_so_far<curr_max)
    {
    max_so_far=curr_max;
    pos=i;
    }
    else
    max_so_far=max_so_far;
    //pos=i;

}
//cout<<“pos=”<<pos<<"
“;
//cout<<“max_so_far=”<<max_so_far<<”
";
//return max_so_far;
long long int max_so_far1=a[pos+k+1];
long long int curr_max1 = a[pos+k+1];
for (i = pos+k+2; i < n; i++)
{
//curr_max1= max(a*,curr_max1+a*);
if(curr_max1+a*>a*)
{
curr_max1=curr_max1+a*;
//pos=i;
}
else
{
curr_max1=a*;
//pos=i;
}

    //max_so_far = max(max_so_far, curr_max);
    if(max_so_far1<curr_max1)
    {
    max_so_far1=curr_max1;
    //pos=i;
    }
    else
    max_so_far1=max_so_far1;
    //max_so_far1= max(max_so_far1,curr_max1);

}
//cout<<“max_so_far1=”<<max_so_far1<<"
";
sum=max_so_far+max_so_far1;
return sum;
}

long long int maxSubArraySum1(long long int a[],long long int size,long long int k,long long int n)
{
long long int max_so_far =a[n-1];
long long int i,pos=n-1;
long long int curr_max =a[n-1];

long long int sum=0;
for (i=n-2; i>=size; i–)
{
//curr_max = max(a*, curr_max+a*);
if(curr_max+a*>a*)
{
curr_max=curr_max+a*;
//pos=i;
}
else
{
curr_max=a*;
//pos=i;
}

    //max_so_far = max(max_so_far, curr_max);
    if(max_so_far<curr_max)
    {
    max_so_far=curr_max;
    pos=i;
    }
    else
    max_so_far=max_so_far;
    //pos=i;

}
//cout<<“pos=”<<pos<<"
“;
//cout<<“max_so_far=”<<max_so_far<<”
";
//return max_so_far;
long long int max_so_far1=a[0];
long long int curr_max1 = a[0];
for (i=1;i<=pos-k-1; i++)
{
//curr_max1= max(a*,curr_max1+a*);
//max_so_far1= max(max_so_far1,curr_max1);
if(curr_max1+a*>a*)
{
curr_max1=curr_max1+a*;
//pos=i;
}
else
{
curr_max1=a*;
//pos=i;
}

    //max_so_far = max(max_so_far, curr_max);
    if(max_so_far1<curr_max1)
    {
    max_so_far1=curr_max1;
    //pos=i;
    }
    else
    max_so_far1=max_so_far1;

}
//cout<<“max_so_far1=”<<max_so_far1<<"
";
sum=max_so_far+max_so_far1;
return sum;
}

int main()
{
long long int t,n,k,i;
long long int sum,sum1;
cin>>t;
//t=in();
while(t–)
{
//max=max1=-1000000001;
sum=sum1=0;
cin>>n>>k;
//n=in();
//k=in();
long long int a[n+1];
for(i=0;i<n;i++)
cin>>a*;
//a*=in();

sum = maxSubArraySum(a,n-k-1,k,n);
sum1=maxSubArraySum1(a,k+1,k,n);
cout<<max(sum,sum1)<<"

";
}
return 0;
}