Cod sursa(job #1333128)

Utilizator cremarencodianaCremarenco Diana cremarencodiana Data 2 februarie 2015 20:29:28
Problema Subsecventa de suma maxima Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.56 kb
#include <cstdio>

using namespace std;
int n,a[6000010],i,m,s,ic,sf,pc;
int main()
{
    freopen("ssm.in","r",stdin);
    freopen("ssm.out","w",stdout);
    scanf("%d\n",&n);
    for (i=1;i<=n; i++)
     scanf("%d ",&a[i]);
    s=a[1]; m=a[1];
    ic=1; pc=1;
    sf=1;
    for (i=2; i<=n; i++)
    {
        if (sc>=0) s+=a[i];
        else
        {
            pc=i; s=a[i];
        }

        if (s>m)
        {
            ic=pc;
            sf=i;
            m=s;
        }
    }
    printf("%d %d %d\n",m,ic,sf);

    return 0;
}