Cod sursa(job #497761)
| Utilizator | Data | 3 noiembrie 2010 11:37:18 | |
|---|---|---|---|
| Problema | Subsecventa de suma maxima | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.43 kb |
#include<fstream>
using namespace std;
ifstream in("ssm.in");
ofstream out("ssm.out");
int main()
{
int x,sc,smax,stc,stmax,drmax,n,i;
sc = 0;
stc = 1;
smax = -2000000000;
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 << smax << ' ' << stmax << ' ' << drmax << '\n';;
return 0;
}
