Cod sursa(job #756730)

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

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

int N, A, S_max = 0, 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;
            //fout << S_max<<'\n';
        }
        if(S < 0 )
            {
                S = 0 , p = i + 1;
            }
    }
    fout<< S_max << " " << p << " " << u;
}
int main()
{
    read();
    fclose(fin);
    return 0;
}