Cod sursa(job #495176)
Utilizator | Data | 24 octombrie 2010 12:42:16 | |
---|---|---|---|
Problema | Subsecventa de suma maxima | Scor | 80 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.36 kb |
#include <stdio.h>
int n,i,in,s,ini,sfi,k;
int max=-1000;
int main()
{
freopen("ssm.in","r",stdin);
freopen("ssm.out","w",stdout);
scanf("%d",&n);
in=1;
for(i=1;i<=n;i++){
scanf("%d",&k);
if(s<0){
in=i;
s=0;
}
s+=k;
if(s>max){
max=s;
ini=in;
sfi=i;
}
}
printf("%d %d %d",max,ini,sfi);
return 0;
}