Cod sursa(job #3328179)

Utilizator David_MateiMatei David Dumitru David_Matei Data 6 decembrie 2025 18:01:51
Problema Subsecventa de suma maxima Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.63 kb
#include <fstream>
#include <climits>

using namespace std;

int main()
{

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

    int n, sc = -1, s_max = INT_MIN, st_c = 0, st_max, dr_max;
    in >> n;
    for ( int i = 1; i <= n; i++ ){
        int x;
        in >> x;
        if ( x > sc + x ){
            sc = x;
            st_c = i;
        }
        else sc += x;

        if ( sc > s_max ){
            s_max = sc;
            st_max = st_c;
            dr_max = i;
        }
    }

    out << s_max << " " << st_max << " " << dr_max << '\n';

    in.close();
    out.close();
    return 0;

}