Cod sursa(job #2921079)

Utilizator PsyDuck1914Feraru Rares-Serban PsyDuck1914 Data 27 august 2022 12:40:47
Problema Subsecventa de suma maxima Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.62 kb
#include <fstream>

using namespace std;

const int INF = 1 << 31;

int main()
{
    ifstream in("ssm.in");
    ofstream out("ssm.out");
    int n;
    int sc = INF, smax = INF, stmax, drmax, stc;
    in >> n;
    for (int i = 1; i <= n; i++)
    {
        int x;
        in >> x;
        if (x > sc + x)
        {
            sc = x;
            stc = i;
        }
        else
        {
            sc += x;
        }
        if (sc > smax)
        {
            smax = sc;
            stmax = stc;
            drmax = i;
        }
    }
    out << smax << " " << stmax << " " << drmax;
    in.close();
    out.close();
    return 0;
}