题目大意:给一组数,求最大连续子序列和。
解题思路:UVA - 507 Jill Rides Again(连续子序列最大和)
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cmath>
#include<string.h>
#include<string>
#include<queue>
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
const int INF = 0x3f3f3f3f;
const int NINF = -INF -1;
const int MAXN = 100000+5;
using namespace std;
int num[MAXN];
int T, n;
int main() {
scanf("%d", &T);
for (int t = 0; t < T; t++) {
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d", &num[i]);
int ans = NINF, sum = 0;
int l = 1, r = 1, bg = 1;
for (int i = 1; i <= n; i++) {
if (sum < 0) {
sum = 0;
bg = i;
}
sum += num[i];
if (sum > ans) {
ans = sum;
l = bg;
r = i;
}
}
if (t) printf("\n");
printf("Case %d:\n", t+1);
printf("%d %d %d\n", ans, l, r);
}
return 0;
}