Pagini recente » Cod sursa (job #618750) | Cod sursa (job #3236390) | Cod sursa (job #2271992) | Cod sursa (job #568126) | Cod sursa (job #3149500)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("ssm.in");
ofstream fout("ssm.out");
int n, x, st, dr, maxim, s, stmax, drmax;
int main()
{
fin >> n >> s;
st = dr = 1;
maxim = s;
for (int i = 2; i <= n; i++) {
fin >> x;
if (s >= 0) {
s += x;
dr = i;
}
else {
s = x;
st = dr = i;
}
if (s > maxim)
maxim = s, stmax = st, drmax = dr;
}
fout << maxim << " " << stmax << " " << drmax;
return 0;
}