Cod sursa(job #2813377)

Utilizator ruxiTTutunaru Ruxandra ruxiT Data 6 decembrie 2021 15:14:58
Problema Subsecventa de suma maxima Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.57 kb
#include <iostream>
#include <fstream>

using namespace std;

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

int main()
{
    int smax, sc = 0, x, n, pc, maxim, pmax;
    fin >> n;
    smax = 1 << 31;
    for ( int i = 0; i < n; i++ )
    {
        fin >> x;
        if ( x > sc + x ) {
            sc = x;
            pc = i;
        } else
            sc += x;
        if ( sc > smax ) {
            smax = sc;
            pmax = pc;
            maxim = i;
        }
    }
    fout << smax << " " << pmax + 1 << " " << maxim + 1;
    return 0;
}