Cod sursa(job #1837810)

Utilizator alexandruchiriacAlexandru Chiriac alexandruchiriac Data 30 decembrie 2016 14:44:14
Problema Subsecventa de suma maxima Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.46 kb
#include <iostream>
#include <fstream>
using namespace std;

ifstream f("ssm.in");
ofstream g("ssm.out");

int n , x , S , Smax , imax , jmax , i , index;

int main()
{
    Smax = -299999999;
    f >> n;
    for ( int i = 1; i <= n ; i++ )
    {
        f >> x;
        if ( S < 0 ) S = x, index = i;
        else S += x;
        if ( Smax < S ) Smax = S , imax = index, jmax = i;
    }
    g << Smax << " " << imax << " " << jmax ;


    return 0;
}