Pagini recente » Cod sursa (job #1445205) | Cod sursa (job #801270) | Cod sursa (job #245316) | Cod sursa (job #730610) | Cod sursa (job #1767297)
#include <fstream>
#include <iostream>
using namespace std;
int main()
{
ifstream fin("ssm.in");
ofstream fout("ssm.out");
int n;
fin >> n;
int smax = -(1 << 30), start, stop;
int curent = 0, st;
for (int i = 1; i <= n; ++i) {
int x;
fin >> x;
curent += x;
if (curent < 0 || st == 0) {
curent = x;
st = i;
}
if (curent > smax) {
smax = curent;
start = st;
stop = i;
}
if (curent < 0)
curent = st = 0;
}
fout << smax << " " << start << " " << stop << "\n";
return 0;
}