题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1003
2 5 6 -1 5 4 -7 7 0 6 -1 1 -6 7 -5
Case 1: 14 1 4 Case 2: 7 1 6
代码如下:
#include <cstdio>
#define INF 0x3f3f3f3f
int main()
{
    int t;
    int n, tt;
    scanf("%d",&t);
    int k = 0;
    while(t--)
    {
        scanf("%d",&n);
        int sum = 0, maxx = -INF;
        int start = 1, endd = 1, pos = 1;
        for(int i = 1; i <= n; i++)
        {
            scanf("%d",&tt);
            sum+=tt;
            if(sum > maxx)
            {
                start = pos;
                endd = i;
                maxx = sum;
            }
            if(sum < 0)
            {
                sum = 0;
                pos = i+1;
            }
        }
        printf("Case %d:\n",++k);
        printf("%d %d %d\n",maxx,start,endd);
        if(t)
            printf("\n");
    }
    return 0;
}
原文:http://blog.csdn.net/u012860063/article/details/39322883