Pagini recente » Cod sursa (job #3195403) | Cod sursa (job #3165652) | Cod sursa (job #2355515) | Cod sursa (job #558816) | Cod sursa (job #3198847)
#include <fstream>
#include <iostream>
using namespace std;
int n, smax=(1<<31), startmax, stopmax;
int main()
{
ifstream fin("ssm.in");
int i, x, sc = 0, stc = 1, stopc = 1;
fin >> n;
for (i = 1; i <= n; i++) {
fin >> x;
sc += x;
if (sc <= 0) {
sc = 0;
stc = i+1;
stopc = i+1;
}
else {
if (sc > smax) {
smax = sc;
startmax = stc;
stopmax = stopc;
}
stopc++;
}
}
fin.close();
ofstream fout("ssm.out");
fout << smax << ' ' << startmax << ' ' << stopmax;
fout.close();
return 0;
}