杭电acm1003的题,出现Runtime Error (ACCESS_VIOLATION)该怎么改
InputThe first line of the input contains an integer T(1<=T<=20) which means the number of test cases. Then T lines follow, each line starts with a number N(1<=N<=100000), then N integers followed(all the integers are between -1000 and 1000).
Output
For each test case, you should output two lines. The first line is "Case #:", # means the number of the test case. The second line contains three integers, the Max Sum in the sequence, the start position of the sub-sequence, the end position of the sub-sequence. If there are more than one result, output the first one. Output a blank line between two cases.
Sample Input
2 5 6 -1 5 4 -7 7 0 6 -1 1 -6 7 -5
Sample Output
Case 1: 14 1 4 Case 2: 7 1 6
/*************************************/
#include <iostream>
using namespace std;
int main()
{
int n,i,k,j,start,finish;
double sum,sum1,max=0;
int a[20];
cin>>n;
for(i=0;i<n;i++)
{
cin>>k;
sum=sum1=0;
for(j=1;j<=k;j++)
{
cin>>a[j];
}
for(j=1;j<=k;j++)
{
sum1=sum;
start=finish=1;
sum=sum+a[j];
if(sum>sum1)
{
max=sum;
finish=j;
}
else{finish=j-1;}
}
cout<<max<<" "<<start<<" "<<finish<<endl;
cout<<endl;
}
return 0;
}