Cod sursa(job #1767297)
| Utilizator | Data | 28 septembrie 2016 21:28:35 | |
|---|---|---|---|
| Problema | Subsecventa de suma maxima | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.68 kb |
#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;
}
