Pagini recente » Cod sursa (job #3255370) | Cod sursa (job #751109) | Cod sursa (job #1611780) | Cod sursa (job #735532) | Cod sursa (job #3151549)
#include <iostream>
#include <fstream>
#include <cstdint>
using namespace std;
int main() {
ifstream fin("ssm.in");
ofstream fout("ssm.out");
int n;
fin >> n;
int firstNr;
fin >> firstNr;
int maxBest = firstNr;
int st = 1, dr = 1, prevBest = firstNr;
int prevBestSt = 1;
for (int i = 2; i <= n; ++i) {
int nr;
fin >> nr;
int best, bestSt;
if (nr + prevBest < nr) {
best = nr;
bestSt = i;
} else {
best = nr + prevBest;
bestSt = prevBestSt;
}
if (best > maxBest) {
maxBest = best;
dr = i;
st = bestSt;
} else if (best == maxBest && bestSt < st) {
st = bestSt;
dr = i;
}
prevBest = best;
prevBestSt = bestSt;
}
fout << maxBest << ' ' << st << ' ' << dr << "\n";
return 0;
}