Cod sursa(job #2700776)

Utilizator cyg_mihaizMIHAI ZARAFIU cyg_mihaiz Data 28 ianuarie 2021 18:56:29
Problema Subsecventa de suma maxima Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.54 kb
#include <fstream>
#include <climits>

using namespace std;

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

int main()
{
    ios_base::sync_with_stdio(false);
    fin.tie(NULL);

    int n,i,x,s,smax,st,dr,aux;
    fin >> n;
    s = 0;
    aux = 1;
    smax = INT_MIN;
    for(i = 1; i <= n; i++)
    {
        fin >> x;
        s = s + x;
        if(s > smax)
            smax = s, dr = i, st = aux;
        if(s < 0)
            s = 0, aux = i + 1;
    }
    fout << smax << " " << st << " " << dr;
    return 0;
}