AcWing 3652. 最大连续子序列
原题链接
简单
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int N = 1e4 + 10;
int t, n, m, k, l, r, op, x, y, maxi, al, ar;
void solve() {
while (cin >> n) {
maxi = -1;
x = 0;
l = r = 0;
for (int i = 1; i <= n; i++) {
cin >> t;
x += t;
if (x < 0) {
x = 0;
l = i;
continue;
}
if (x > maxi) {
maxi = x;
al = l;
ar = i - 1;
}
}
if (maxi == -1) {
cout << "0 0 0";
} else {
cout << maxi << " " << al << " " << ar;
}
cout << "\n";
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
solve();
return 0;
}