Pagini recente » Cod sursa (job #1061781) | Cod sursa (job #1897833) | Cod sursa (job #1311954) | Cod sursa (job #2409343) | Cod sursa (job #2680957)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("ssm.in");
ofstream g("ssm.out");
int main() {
int S = 0, n, x, start = 0, st, dr, S_max = 0, len = 0, len_S_max = 6000000;
f >> n;
st = dr = 1;
for (int i = 1; i <= n; i++) {
f >> x;
if (S < 0) {
S = 0;
start = i;
}
S += x;
if (S > S_max) {
S_max = S;
dr = i;
st = start;
len_S_max = len;
len = 0;
} else if (S == S_max && len < len_S_max) {
S_max = S;
dr = i;
st = start;
len_S_max = len;
len = 0;
}
len++;
}
g << S_max << ' ' << st << ' ' << dr;
f.close();
g.close();
return 0;
}