Pagini recente » Cod sursa (job #2373041) | Cod sursa (job #1905290) | Cod sursa (job #2653316) | Cod sursa (job #2124960) | Cod sursa (job #3167565)
#include <bits/stdc++.h>
#include <random>
#include <chrono>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const char nl = '\n';
const char sp = ' ';
const int inf = 0x3f3f3f3f;
const long long INF = 1000000000000000000;
const int mod = 1e9 + 7;
const char out[2][4]{ "NO", "YES" };
#define all(A) A.begin(), A.end()
using ll = long long;
ifstream fin("ssm.in");
ofstream fout("ssm.out");
#define variableName(var) #var
#define __debug(var) cout << #var << " = " << var << '\n'
inline int rint(int a, int b) { return uniform_int_distribution<int>(a, b)(rng); }
const int nmax = 6e6;
int n, x;
struct solution {
int start;
int lenght;
ll sum;
bool operator>(const solution& other) {
if (sum != other.sum) {
return sum > other.sum;
}
if (start != other.start) {
return start < other.start;
}
return lenght < other.lenght;
}
solution& operator=(const solution& other) {
start = other.start;
lenght = other.lenght;
sum = other.sum;
return *this;
}
};
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
fin >> n >> x;
solution best{ 1, 1, x };
solution curr{ 1, 1, x };
for (int i = 2; i <= n; ++i) {
fin >> x;
curr.lenght++, curr.sum += x;
solution ncurr{ i, 1, x };
if (ncurr > curr) {
curr = ncurr;
}
if (curr > best) {
best = curr;
}
}
fout << best.sum << sp << best.start << sp << best.start + best.lenght - 1;
}