Cod sursa(job #756727)

Utilizator Theorytheo .c Theory Data 10 iunie 2012 13:12:46
Problema Subsecventa de suma maxima Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.61 kb
#include<stdio.h>
#include<fstream>

#define nmax 6000004
using namespace std;
FILE *fin = fopen("ssm.in", "rt");
ofstream fout("ssm.out");

long long N, A, S_max = -100, S = 0 ;
int p  = 1, u;

void read()
{
    fscanf(fin, "%d", &N);
    for(int i = 1; i <= N; i++)
    {
        fscanf(fin, "%d", &A);
        S += A;
        if(S > S_max)
        {
            S_max = S;
            u = i;
        }
        if(S< 0 )
            {
                S = 0 , p = i + 1;
            }
    }
    fout<< S << " " << p << " " << u;
}
int main()
{
    read();
    fclose(fin);
    return 0;
}