Pagini recente » Cod sursa (job #1081494) | Cod sursa (job #439782) | Rating Ianis Droana Gabriel (ianisdroana) | Cod sursa (job #2118455) | 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;
}