Cod sursa(job #3283488)

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

using namespace std;

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

const int INF = 2e9;
const int N = 5000000;
int v[N];

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++)
    {
        in >> v[i];
        if (s_c > 0)
        {
            s_c += v[i];
            dr = i;
        }
        else
        {
            s_c = v[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;
}