Cod sursa(job #2290303)
Utilizator | Nicola Victor Teodor Victoras2006 | Data | 26 noiembrie 2018 11:43:55 |
---|---|---|---|
Problema | Subsecventa de suma maxima | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.58 kb |
#include <fstream>
using namespace std;
int main() {
ifstream fin( "ssm.in" );
ofstream fout( "ssm.out" );
int n, a, sum, st, dr, smax, i, x, y;
fin >> n;
smax = 1 << 31;
sum = 0;
x = 1;
for ( i = 0; i < n; i ++ ) {
fin >> a;
if ( sum < 0 ) {
sum = a;
x = y = i + 1;
}
else {
sum += a;
y = i + 1;
}
if ( sum > smax ) {
smax = sum;
st = x;
dr = y;
}
}
fout << smax << " " << st << " " << dr << "\n";
return 0;
}