Cod sursa(job #756733)

Utilizator Theorytheo .c Theory Data 10 iunie 2012 13:21:09
Problema Subsecventa de suma maxima Scor 90
Compilator cpp Status done
Runda Arhiva educationala Marime 0.73 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 = -1000000, 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;
            }
    }
    if(S_max >= 0)
    fout<< S_max << " " << p << " " << u;
    else
        fout<< S_max << " " << u << " " << u;
}
int main()
{
    read();
    fclose(fin);
    return 0;
}