Pagini recente » Cod sursa (job #444093) | Cod sursa (job #280077) | Cod sursa (job #1961473) | Cod sursa (job #1664490) | Cod sursa (job #1362517)
#include<cstdio>
#include<string>
using namespace std;
#ifdef HOME
const string inputFile = "input.txt";
const string outputFile = "output.txt";
#else
const string problemName = "ssm";
const string inputFile = problemName + ".in";
const string outputFile = problemName + ".out";
#endif
const int INF = (1 << 30);
int N, meilleur, debut, fin;
int main() {
int i, x, best, start, end;
freopen(inputFile.c_str(), "r", stdin);
freopen(outputFile.c_str(), "w", stdout);
scanf("%d", &N);
meilleur = best = -INF;
for(i = 1; i <= N; i++) {
scanf("%d", &x);
if(best + x < x) {
best = x;
start = i;
end = i;
} else {
best += x;
end = i;
}
if((best > meilleur) || (best == meilleur && start < debut) || (best == meilleur && start == debut && end < fin)) {
meilleur = best;
debut = start;
fin = end;
}
}
printf("%d %d %d\n", meilleur, debut, fin);
return 0;
}