Cod sursa(job #3283491)

Utilizator roberttbhMarinescu Robert roberttbh Data 9 martie 2025 18:14:29
Problema Subsecventa de suma maxima Scor 95
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.77 kb
#include <fstream>

using namespace std;

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

const int INF = 2e9;

int main()
{
    int n;
    in >> n;
    int s_max = -INF, s_c = 0;
    int st, dr, st_max, dr_max;
    st = dr = st_max = dr_max = 0;
    for (int i = 0; i < n; i++)
    {
        int x_i;
        in >> x_i;
        if (s_c > 0)
        {
            s_c += x_i;
            dr = i;
        }
        else
        {
            s_c = x_i;
            st = dr = i;
        }
        if (s_c > s_max)
        {
            s_max = s_c;
            dr_max = dr;
            st_max = st;
        }
    }
    dr_max++;
    st_max++;
    out << s_max << ' ' << st_max << ' ' << dr_max;
    in.close();
    out.close();
    return 0;
}