题目描述
blablabla
样例
#include<iostream>
#include<algorithm>
using namespace std;
const int N = 1e5 + 10;
int a[N];
int s[N];
int f[N];
int main()
{
int k;
while (cin>>k) {
int result = -10;
int l, r;
int mi = s[0], temp = 1;
for (int i = 1; i <= k; i++) scanf("%d", &a[i]);
for (int i = 1; i <= k; i++) s[i] = s[i - 1] + a[i];
for (int i = 1; i <= k; i++) {
if(s[i-1]<mi) mi = s[i - 1], temp = i;
f[i] = s[i] - mi;
if(f[i]>result) result = f[i], l = temp, r = i;
}
if(result<0) printf("0 0 0\n");
else{ printf("%d %d %d\n", result, l-1, r-1);}
}
return 0;
}
算法1
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
blablabla
算法2
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
blablabla