Pagini recente » Cod sursa (job #1117602) | Cod sursa (job #261973) | Cod sursa (job #2447191) | Cod sursa (job #1161995) | Cod sursa (job #3236719)
#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 currVal;
fin >> currVal;
int rg = 1;
int lf = 0;
int bestVal = -INF;
int bestLf;
int bestRg;
for (int i = 1; i < n; i++) {
int x;
fin >> x;
if (currVal + x > x) {
currVal = currVal + x;
rg = i;
}
else {
currVal = x;
rg = i;
lf = i;
}
if (currVal > bestVal) {
bestVal = currVal;
bestLf = lf;
bestRg = rg;
}
}
fout << bestVal << ' ' << bestLf + 1 << ' ' << bestRg + 1 << '\n';
return 0;
}