Cod sursa(job #3343355)

Utilizator Alias47John Doe Alias47 Data 27 februarie 2026 09:00:37
Problema Subsecventa de suma maxima Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.6 kb
//#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;


string file = "ssm";
ifstream f(file + ".in");
ofstream g(file + ".out");



int main()
{
    long long n, x, i, sum = 0, st = 1, stmax = 0, drmax = 0, maxx = -2000000000;
    f >> n;
    for (i = 1; i <= n; i++)
    {
        f >> x;
        if (sum < 0)
            sum = x, st = i;
        else
            sum += x;
        if (sum > maxx) {
            maxx = sum;
            stmax = st;
            drmax = i;
        }
    }
    g << maxx << " " << stmax << " " << drmax;
    return 0;

}