# KCON help WA

Can anyone help me in understanding what’s wrong with my code.
I have tried various test cases manually and i am getting right answer, but in codechef
compiler most of the cases are coming W.A .
Question :https://www.codechef.com/LRNDSA06/problems/KCON

logic is standard (k-2)*sum of array + kadane for 2A , and all k values are handled as well ,
At the end i have done modulo

``````#include<iostream>
#include<math.h>
using namespace std;

int main()
{
const unsigned int mx = 1000000007;
long long int t;
cin>>t;

///1 -2 1 1 -2 1
while(t!=0)
{
long long int n,k;
cin>>n>>k;
long long int a[100000];
long long int nsum = 0;

for(long long int i=0;i<n;i++)
{
cin>>a[i];
nsum = nsum + a[i];

}
if(k==1)
{
long long int sumi = 0;
long long int maxi = 0;
for(long long int i=0;i<n;i++)
{
sumi = sumi + a[i];
if(sumi<0)
{
sumi = 0;
}
if(sumi>maxi)
{
maxi = sumi ;
}
}
maxi = maxi % mx;

cout<<maxi<<endl;
}

else
{

long long int maxi = 0;
long long int x= 2;
long long int sumi = 0;
while(x!=0)
{
for(long long int i=0;i<n;i++)
{
sumi = sumi + a[i];
if(sumi<0)
{
sumi = 0;
}
if(sumi>maxi)
{
maxi = sumi ;
}
}

x--;
}

if(nsum>0)
{
nsum = nsum *(k-2);
maxi = maxi + nsum ;
}

maxi = maxi % mx;

cout<<maxi<<endl;
}

t--;

}

}``````