#include <cstdio>
#include <map>
using namespace std;
int main()
{
map<int, int> from;
int N, L[10000], sum[10000], Max = 0;
scanf("%d", &N);
for( int i = 0; i < N; ++i )
scanf("%d", &L[i]);
from[0] = 0;
sum[0] = L[0];
for( int i = 1; i < N; ++i )
if( sum[ i - 1 ] + L[i] < L[i] )
{
sum[i] = L[i];
from[i] = i;
}
else
{
sum[i] = sum[ i - 1 ] + L[i];
from[i] = from[ i - 1 ];
}
for( int i = 0; i < N; ++i )
if( sum[Max] < sum[i] )
Max = i;
if( sum[Max] < 0 )
printf("0 %d %d", L[0], L[N - 1]);
else
printf("%d %d %d", sum[Max], L[from[Max]], L[Max]);
}
PAT A 1007 Maximum Subsequence Sum (25 分)(待补充)
最新推荐文章于 2022-06-12 00:02:02 发布