Cod sursa(job #1892081)

Utilizator Storm_FireFox1Matei Gardus Storm_FireFox1 Data 24 februarie 2017 17:19:36
Problema Subsecventa de suma maxima Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.57 kb
#include <fstream>

using namespace std;

ifstream fin("ssm.in");
ofstream fout("ssm.out");

const int inf = 1e9;

int main()
{
    int n;
    fin >> n;
    int s = 0, sol = -inf, x = 1, solx, soly;
    for(int i = 1; i <= n; i++)
    {
        int a;
        fin >> a;
        s = s + a;
        if(s > sol)
        {
            sol = s;
            solx = x;
            soly = i;
        }
        if(s < 0)
        {
            s = 0;
            x = i + 1;
        }
    }
    fout << sol << " " << solx << " " << soly << "\n";
    return 0;
}