Cod sursa(job #2731246)

Utilizator VladPislaruPislaru Vlad Rares VladPislaru Data 27 martie 2021 16:32:14
Problema Subsecventa de suma maxima Scor 95
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.7 kb
#include <bits/stdc++.h>
#define oo 1000000000
using namespace std;

ifstream fin ("ssm.in");
ofstream fout ("ssm.out");
int n, s[6000005], ind[6000005];

int main()
{
    int i, x, minim,indminim,summax = -oo,p1,p2, v;
    fin >> n;
    v = 0;
    s[0] = 0;
    ind[0] = 0;
    for (i = 1; i <= n; i++)
    {
        fin >> x;
        s[i] = x;
        ind[i] = i;
        if (s[i] < s[i - 1] + x)
        {
            s[i] = s[i - 1] + x;
            ind[i] = ind[i - 1];
        }
        if (summax < s[i])
        {
            summax = s[i];
            p1 = ind[i];
            p2 = i;
        }
    }
    fout << summax << " " << p1 << " " << p2 << "\n";
    return 0;
}