Cod sursa(job #2574198)

Utilizator VNohaiNohai Vlad-Auras VNohai Data 5 martie 2020 20:54:31
Problema Subsecventa de suma maxima Scor 60
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.51 kb
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define NMAX 200000

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

int n, af, start, stop, x, _max, afstart;

int main()
{
    fin>>n;
    fin>>af;
    _max=af;
    start=1, stop=1;
    for(int i=2; i<=n; i++)
    {
    fin>>x;
    if(af+x>x) {af=af+x; if(_max<af) _max=af, afstart=start, stop=i;}
    else start=i, af=x;
    cout<<af<<" ";
    }
    fout<<_max<<" "<<afstart<<" "<<stop;
}