文章
17
粉丝
166
获赞
6
访问
144.5k
#include <bits/stdc++.h>
using namespace std;
const int N = 10010;
int dp[N];
int maxx;
int a[N];
int n, flag;
int main()
{
while (cin >> n)
{
flag = 0;
if(n == 0) break;
for(int i = 0; i < n; i++)
{
cin >> a[i];
if(a[i] >= 0) flag = 1;
}
int start = a[0], end = a[n - 1], e = n - 1, s = 0;
dp[0] = a[0];
maxx = a[0];
for(int i = 1; i < n; i++)
{
dp[i] = max(dp[i - 1] + a[i], a[i]);
if(dp[i] > maxx)
{
maxx = dp[i];
end = a[i];
e = i, start = s;
}
if(a[i - 1] <= 0 && a[i] >= 0 && dp[i] == a[i])
s = a[i];
}
if(flag) printf("%d %d %d", maxx, start, end);
else printf("%d %d %d", 0, a[0], a[n - 1]);
cout << endl;
}
...
登录后发布评论
暂无评论,来抢沙发