Pagini recente » Cod sursa (job #588277) | Cod sursa (job #385577) | Cod sursa (job #2715676) | Cod sursa (job #2442061) | Cod sursa (job #2832059)
#include <bits/stdc++.h> /* printf, scanf, puts, NULL */
#include <stdlib.h> /* srand, rand */
#include <time.h>
using namespace std;
ifstream fin("ssm.in");
ofstream fout("ssm.out");
int main() {
int n, x, max = INT_MIN, start, finish, s = 0, startMax;
fin >> n;
for (int i = 1; i <= n; i ++) {
fin >> x;
if (s + x > x) {
s += x;
}
else {
s = x;
start = i;
}
if (max < s) {
finish = i;
startMax = start;
max = s;
}
// else if (max == s) {
// if (finish - startMax > i - start) {
// finish = i;
// startMax = start;
// }
// }
}
fout << max << ' ' << startMax << ' ' << finish;
return 0;
}