#include <vector>
#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
int k;
int temp;
int i;
vector<int> a;
int nowLeft, nowRight, left, right, nowMax, max;
int t = n;
while (n--)
{
a.clear();
cin >> k;
while (k--)
{
cin >> temp;
a.push_back(temp);
}
nowLeft = nowRight = nowMax = left = right = 0;
max = INT_MIN;
for (i = 0; i < a.size(); i++)
{
nowMax += a[i];
nowRight = i;
if (max < nowMax)
{
max = nowMax;
left = nowLeft;
right = nowRight;
}
if(nowMax < 0)
{
nowMax = 0;
nowLeft = nowRight = i + 1;
}
}
cout << "Case " << t - n << ":" << endl;
cout << max << " " << left + 1 << " " << right + 1 << endl;
if (n >= 1)
cout << endl;
}
return 0;
}
hduoj_1003 最大连续子串和
最新推荐文章于 2019-08-21 23:36:48 发布