#include <iostream>
using namespace std;
int main(){
int t;
long x, n, sum, max, head, tail, index, Head, Tail, i;
cin >> t;
for(i = 0; i < t; i++){
cin >> n;
head = 1;
tail = 1;
sum = 0;
max = -32768; //!设为极小值以免样例中极负数的影响
Tail = 0;
Head = 0;
for(index = 1; index <= n; index++){
cin >> x;
sum += x;
if(sum>max){
max = sum;
tail = index;
Head = head;
Tail = tail;
}
if(sum<0){
head = index + 1;
sum = 0;
}
}
cout<<"Case "<<(i+1)<<":\n"<<max<<" "<<Head<<" "<<Tail<<"\n";
if(i<(t-1)) cout<<"\n";
}
return 0;
}
- 注意每个案例前初始化变量,避免遗留数据影响
- 将max初始化为最负值,避免极端测试值影响