Cod sursa(job #2344720)

Utilizator mihaigeorgemihai george mihaigeorge Data 15 februarie 2019 15:31:50
Problema Subsecventa de suma maxima Scor 80
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.52 kb
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("ssm.in");
ofstream fout ("ssm.out");
int x;
long long s, smax, imax;
int jmax, i, j, n;
int main()
{
    fin >> n >> x;
    for(i = 2 ; i <= n ; ++i)
    {
        fin >> x;
        if(x < s+x)
            s += x;
        else
        {
            s = x;
            imax = i;
        }
        if(s > smax)
        {
            smax = s;
            jmax = i;
        }
    }
    fout << smax << " " << imax << " " << jmax;

    return 0;
}