Cod sursa(job #3342142)

Utilizator vlad.perpegel2010Vlad Perpegel vlad.perpegel2010 Data 23 februarie 2026 10:15:29
Problema Subsecventa de suma maxima Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.63 kb
#include <fstream>

using namespace std;
ifstream in("ssm.in");
ofstream out("ssm.out");
int main() {
    int n;
    in >> n;
    long long s_max = -2000000001;
    long long s_curr = -2000000001;
    int st = 0, dr = 0, st_curr = 1;
    for (int i = 1; i <= n; ++i) {
        int x;
        in >> x;
        if (s_curr < 0) {
            s_curr = x;
            st_curr = i;
        } else {
            s_curr += x;
        }

        if (s_curr > s_max) {
            s_max = s_curr;
            st = st_curr;
            dr = i;
        }
    }
    out << s_max << " " << st << " " << dr << "\n";
    return 0;
}