Cod sursa(job #279754)

Utilizator ktalyn93Catalin ktalyn93 Data 12 martie 2009 22:53:40
Problema Subsecventa de suma maxima Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 0.79 kb
#include <stdio.h>
int n,j,a[6000000],i,max,s[6000000],d,st,st2;
int main()
{
    freopen("ssm.in","r",stdin);
    freopen("ssm.out","w",stdout);
    scanf("%d",&n);
    for(i=1;i<=n;i++)
     scanf("%d",&a[i]);
   
    s[0]=0;
    max=a[1];
    
    for(i=1;i<=n;i++)
    {
                     s[i]=s[i-1]+a[i];
                     if(s[i]>max)
                     {
                                 max=s[i];
                                
                                 d=i; 
                               
                                 
                     }
                     if(s[i]<0)
                     {
                      s[i]=0;
                      st=i+1;
                      }
    }
   
    printf("%d %d %d",max,st,d);
    return 0;
}