hdu 1231 最大连续和

题意:给定一组数,求最大的连续和,且输出开始与结尾


#include<iostream>
#include<cstdio>

using namespace std;

int s[10011];

int main(){
    int k,n,i,j,maxn,start,end;
    while(cin>>n,n){
        maxn=-100;
        k= start = end  = j = 0;
        for(i=0;i<n;i++){
            scanf("%d",s+i);
            if(k+s[i]<s[i]){
                k=s[i];
                j = i;
            }
            else{
                k+=s[i];
            }
            if(maxn < k){
                maxn = k;
                start = j;
                end = i;
            }
        }
        if(maxn<0)
            printf("0 %d %d\n",s[0],s[n-1]);
        else
            printf("%d %d %d\n",maxn,s[start],s[end]);
    }
    return 0;
}



 

posted @ 2014-09-25 22:01  某某璀  阅读(192)  评论(0编辑  收藏  举报
levels of contents