Cod sursa(job #3328178)

Utilizator rapidu36Victor Manz rapidu36 Data 6 decembrie 2025 18:00:41
Problema Subsecventa de suma maxima Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.71 kb
#include <fstream>
#include <climits>

using namespace std;

int main()
{
    ifstream in("ssm.in");
    ofstream out("ssm.out");
    int n, sc_i = -1, st_c = 0, s_max = INT_MIN, st_max = -1323, dr_max = -878734;
    in >> n;
    for (int i = 1; i <= n; i++)
    {
        int x_i;
        in >> x_i;
        if (x_i > sc_i + x_i)
        {
            sc_i = x_i;
            st_c = i;
        }
        else
        {
            sc_i += x_i;
        }
        if (sc_i > s_max)
        {
            s_max = sc_i;
            st_max =st_c;
            dr_max = i;
        }
    }
    out << s_max << " " << st_max << " " << dr_max << "\n";
    in.close();
    out.close();
    return 0;
}