the description of the test reads_emphasized text_ "You are given a one dimensional array that may contain both positive and negative integers, find the sum of contiguous subarray of numbers which has the largest sum. For example, if the given array is {-2, -5, 6, -2, -3, 1, 5, -6}, then the maximum subarray sum is 7. "emphasized text
I am not able to understand how the sum is when it should be 6.
Also I made a program but it shows wrong answer so i think i am not able to understand the problem.
My code is as follows
#include
#include
#include
using namespace std;
int main() {
long long int n;
cin>>n;
for(long long int k=0;k<n;k++){
long long int t;
cin>>t;
long long int a[t];
for(long long int i=0;i<t;i++){
cin>>a[i];
}
long long int Max=0;
long long int sum=0;
long long int start;
long long int start_step=0;
while(start_step<t){
if(a[start_step]>0){
sum+=a[start_step];
}
if(sum>Max){
Max=sum;
}
else if((a[start_step]<0)){
sum=0;
}
start_step++;
}
cout<<Max<<endl;
}
}