Cod sursa(job #2642999)

Utilizator cyg_dawidDavid Ghiberdic cyg_dawid Data 18 august 2020 10:20:45
Problema Subsecventa de suma maxima Scor 95
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.57 kb
#include <fstream>
#include <algorithm>

using namespace std;

int n, mmax, last, x, st, dr, provisory_st;

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

int main()
{
    fin >> n >> x;
    mmax = last = x; st = dr = provisory_st = 1;
    for(int i = 2; i <= n; i++) {
        fin >> x;
        last = max(last + x, x);
        if(last == x) {
            provisory_st = i;
        }
        if(last > mmax) {
            mmax = last;
            dr = i; st = provisory_st;
        }
    }
    fout << mmax << " " << st << " " << dr;
    return 0;
}