Pagini recente » Cod sursa (job #3177289) | Cod sursa (job #3188475) | Cod sursa (job #3236732)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("ssm.in");
ofstream fout("ssm.out");
const int MAX_N = 6000005;
const int INF = 1 << 31;
int n;
int dp[MAX_N];
int main() {
fin >> n;
int currSum = 0;
int startingIdx;
int bestSum = -INF;
int bestLf;
int bestRg;
for (int i = 0; i < n; i++) {
int x;
fin >> x;
if (currSum < 0) {
currSum = x;
startingIdx = i;
}
else {
currSum += x;
}
if (bestSum < currSum) {
bestSum = currSum;
bestLf = startingIdx;
bestRg = i;
}
}
fout << bestSum << ' ' << bestLf + 1 << ' ' << bestRg + 1 << '\n';
return 0;
}