Max Sum

Max Sum

http://acm.hdu.edu.cn/showproblem.php?pid=1003

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+7;
const int inf=0x8fffffff;
int main()
{
    int i,j,k,m,n,t,tt=0;
    cin>>t;
    while(t--)
    {
        int tmp,a,from,to,c,now,ans;
        cin>>n>>tmp;
        from=to=a=1;
        ans=now=tmp;
        for(i=2;i<=n;i++)
        {
            cin>>tmp;
            if(now<0){now=tmp;a=i;}
            else now+=tmp;
            if(now>ans)
            {
                ans=now;from=a;to=i;
            }
        }
        cout<<"Case "<<++tt<<":"<<endl;
        cout<<ans<<" "<<from<<" "<<to<<endl;
        if(t!=0) cout<<endl;
    }
    return 0;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章