Pagini recente » Cod sursa (job #2585351) | Cod sursa (job #1606088) | Cod sursa (job #1957993) | Cod sursa (job #1615427) | Cod sursa (job #3207211)
#include <fstream>
#include <vector>
std::ifstream fin("ssm.in");
std::ofstream fout("ssm.out");
const int N = 6e6, oo = -2e9;
int n;
std::vector<int> a, best;
int main () {
fin >> n;
for(int i = 0; i < n; ++i){
int x;
fin >> x;
a.push_back(x);
}
int bestSum = oo, st = 0, dr = 0, maxSt = 0, maxDr = 0;
best.push_back(a[0]);
for(int i = 1; i < n; ++i) {
if(a[i] > a[i] + best[i - 1]) {
best.push_back(a[i]);
st = i, dr = i;
}
else {
best.push_back(a[i] + best[i - 1]);
dr++;
}
if(best[i] > bestSum) {
bestSum = best[i];
maxSt = st, maxDr = dr;
}
}
maxSt++, maxDr++;
fout << bestSum << ' ' << maxSt << ' ' << maxDr << '\n';
fin.close();
fout.close();
return 0;
}