#include<iostream>
#include<vector>
using namespace std;
int main()
{
int n;
while((cin>>n)!=NULL)
{
vector<int> number;
int temp;
for(int i=0;i<n;i++)
{
cin>>temp;
number.push_back(temp);
}
int maxsum=-1,indexsum=0,left=number[0],right=number[n-1],curleft=number[0];
for(int i=0;i<n;i++)
{
indexsum+=number[i];
if(indexsum>maxsum)
{
maxsum=indexsum;
right=number[i];
left=curleft;
}
else if(indexsum<0)
{
indexsum=0;
if(i!=n-1)
curleft=number[i+1];
}
}
if(-1==maxsum)
maxsum=0;
cout<<maxsum<<" "<<left<<" "<<right<<endl;
}
return 0;
}
01-复杂度2. Maximum Subsequence Sum (25)
最新推荐文章于 2021-11-26 22:01:02 发布