Pagini recente » Cod sursa (job #1129083) | Cod sursa (job #48220) | Cod sursa (job #2730932) | Cod sursa (job #1614074) | Cod sursa (job #2858023)
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include "bits/stdc++.h"
using namespace std;
using ld = long double;
using ll = long long;
using ull = unsigned long long;
#if defined(ONPC)
#include "bits/debug.h"
#endif
ifstream fin("ssm.in");
ofstream fout("ssm.out");
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(0);
int N;
fin >> N;
vector<int> v(N);
for (int &x : v) fin >> x;
int ans = 0, best = 0;
pair<int, int> best_ind = {0, 0}, ans_ind = {0, 0};
for (int i = 0; i < N; ++i) {
int new_sum = best + v[i];
if (new_sum > v[i]) {
best = new_sum;
best_ind.second = i;
} else {
best = v[i];
best_ind = {i, i};
}
if (best > ans) {
ans = best;
ans_ind = best_ind;
} else if (best == ans) {
int ans_len = ans_ind.second - ans_ind.first + 1;
int best_len = best_ind.second - best_ind.first + 1;
if (best_len < ans_len) {
ans_ind = best_ind;
}
}
}
fout << ans << ' ' << ans_ind.first + 1 << ' ' << ans_ind.second + 1 << "\n";
}