比赛 |
线段数树状数组 |
评测结果 |
AAAAAAAAAA |
题目名称 |
单子序列最大和 |
最终得分 |
100 |
用户昵称 |
jekyll |
运行时间 |
0.067 s |
代码语言 |
C++ |
内存使用 |
3.37 MiB |
提交时间 |
2018-06-18 22:15:23 |
显示代码纯文本
#include<iostream>
#include<cstdio>
using namespace std;
const int INF = 1e9;
const int MAXN = 200010;
int n;
int minp, maxn = -INF, lans, rans;
int a[MAXN], b[MAXN], c[MAXN], sum[MAXN];
int main()
{
freopen("subq.in", "r", stdin);
freopen("subq.out", "w", stdout);
cin >> n;
for (int i = 1; i <= n; ++i)
cin >> a[i], sum[i] = sum[i-1] + a[i];
b[1] = a[1]; c[1] = 1;
if (a[1] < sum[minp]) minp = 1;
for (int i = 2; i <= n; ++i)
{
b[i] = sum[i] - sum[minp];
c[i] = minp + 1;
if (sum[i] < sum[minp]) minp = i;
}
// for (int i = 1; i <= n; ++i) cout << c[i] << ' '; cout << endl << endl;
for (int i = 1; i <= n; ++i)
if (b[i] > maxn) lans = c[i], rans = i, maxn = b[i];
printf("%d\n%d\n%d", lans, rans, maxn);
}