Cod sursa(job #2683906)

Utilizator cristiWTCristi Tanase cristiWT Data 12 decembrie 2020 11:03:58
Problema Subsecventa de suma maxima Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.64 kb
#include <fstream>
#include <vector>

using namespace std;

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

vector <int> v;
vector <int> dp;

int n, p1, p2, LMAX = -1000000, x, nr, s;

int main()
{
    f >> n;
    for (int i=1; i<=n; i++)
    {
        f >> x;
        v.push_back(x);
    }

    for (int i=1; i<v.size(); i++)
    {
        if (dp[i-1] + v[i] >= 0)
            dp.push_back(dp[i-1] + v[i]);
        else dp.push_back(v[i]), nr = i;

        if (dp[i] > LMAX)
        {
            s = dp[i];
            p1 = nr;
            p2 = i;
        }
    }

    g << s << ' ' << p1 << ' ' << p2 << '\n';
}