Cod sursa(job #292118)
Utilizator | Otilia Stretcu otilia_s | Data | 30 martie 2009 19:35:48 |
---|---|---|---|
Problema | Subsecventa de suma maxima | Scor | 95 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.39 kb |
#include <fstream.h>
int n;
int main()
{
ifstream fin("ssm.in");
fin>>n;
int now, MaxS=now=-32767;
int pr,ul,a,b,x;
a=b=pr=ul=0;
while (b<n)
{
fin>>x;
if (now>0) {now+=x; b++;}
else {now=x; a=++b;}
if (MaxS<now) {MaxS=now; pr=a; ul=b;}
}
fin.close();
ofstream fout("ssm.out");
fout<<MaxS<<" "<<pr<<" "<<ul<<"\n";
fout.close();
return 0;
}