General question:
Enter a series to find the sum of the numbers from which to which, that is, the maximum substring (differentiated from the subsequence)
The maximum value of the output substring has already been the subscript at the beginning and end of the maximum substring, and is output.
!!! At the beginning, I defined max =-1, ignoring the possibility that the sum of several numbers may be smaller than-1 .....
[Cpp]
# Include <iostream>
Using namespace std;
Int a [100000] = {0 };
Void main ()
{
Int t, n;
Int max = 0;
Cin> t;
For (int j = 1; j <= t; j ++)
{
Cin> n;
Int sum = 0, temp = 0, B = 0, e = 0;
For (int max =-10000, I = 0; I <n; I ++) // I wrote-1 at the time and called it for a long time. I did not expect this error.
{
Cin> a [I];
If (sum> = 0)
{
Sum + = a [I];
}
Else
{
Sum = a [I];
Temp = I;
}
If (sum> max)
{
Max = sum;
B = temp;
E = I;
}
}
Printf ("Case % d: \ n", j );
Printf ("% d \ n", max, B + 1, e + 1 );
If (j <t)
Cout <endl;
}
}