Cod sursa(job #1452250)
| Utilizator | Data | 20 iunie 2015 14:10:30 | |
|---|---|---|---|
| Problema | Subsecventa de suma maxima | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.6 kb |
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream in("ssm.in");
ofstream out("ssm.out");
int i, n, sc = -1, stc, stmax, drmax, smax = -2000000000, x;
in>>n;
for ( i = 1; i <= n; i++ )
{
in>>x;
if ( sc < 0 )
{
sc = 0;
stc = i;
}
sc += x;
if ( sc > smax )
{
smax = sc;
stmax = stc;
drmax = i;
}
out << sc << " " << smax << "\n";
}
out<<smax<<' '<<stmax+1<<' '<<drmax;
return 0;
}
