Cod sursa(job #2358417)

Utilizator riordache58Razvan Iordache riordache58 Data 28 februarie 2019 08:44:09
Problema Subsecventa de suma maxima Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.62 kb
#include <bits/stdc++.h>
#include <fstream>

using namespace std;

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

long long int i, i1 , max1 = -2100000 , x , pozi , pozj , suma = -1 , n;

int main()
{
    f >> n;

    for ( i = 1 ; i <= n ; i ++ )
    {
        f >> x;

        if ( suma >= 0 )
            suma = suma + x;

        else
        {
            i1 = i;

            suma = x;
        }

        if ( suma > max1 )
        {
            max1 = suma;

            pozi = i1;

            pozj = i;
        }
    }

    g << max1 << " " << pozi << " " << pozj;

    return 0;
}