Cod sursa(job #263240)
| Utilizator | Data | 20 februarie 2009 00:24:25 | |
|---|---|---|---|
| Problema | Subsecventa de suma maxima | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.38 kb |
#include <stdio.h>
long n,s,smax,i,x,p,u,P,U;
int main()
{
freopen("ssm.in", "r", stdin);
freopen("ssm.out", "w", stdout);
scanf("%ld %ld", &n, &x);
s=x; smax=x; p=1; u=1;
for (i=2;i<=n;++i)
{
scanf("%ld", &x);
if (s+x<x) { s=x, p=u=i;}
else { s=s+x,++u;}
if (s>smax){ smax=s, P=p, U=u;}
}
printf("%ld %ld %ld",smax,P,U);
return 0;
}