Cod sursa(job #2473949)
Utilizator | Nicola Victor-Teodor Victor2006 | Data | 14 octombrie 2019 15:39:03 |
---|---|---|---|
Problema | Subsecventa de suma maxima | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.53 kb |
#include <iostream>
#include <fstream>
#define INF 2000000000
using namespace std;
ifstream fin ( "ssm.in" );
ofstream fout ( "ssm.out" );
int main() {
long long n, a, sc, i, smax, start, stop, sstart;
fin >> n;
sc = smax = -INF;
start = stop = -1;
for ( i = 0; i < n; i ++ ) {
fin >> a;
if ( sc < 0 ) {
sc = 0;
sstart = i + 1;
}
sc += a;
if ( sc > smax ) {
smax = sc;
stop = i + 1;
start = sstart;
}
}
fout << smax << " " << start << " " << stop << "\n";
return 0;
}