Pagini recente » Cod sursa (job #1162890) | Cod sursa (job #3248010) | Cod sursa (job #2820193) | Cod sursa (job #2608841) | Cod sursa (job #1767298)
#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 = 0, stop = 0;
int curent = 0, st = 0;
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;
}