Cod sursa(job #2428157)

Utilizator Ionut28Porumb Palincas Ionut Ionut28 Data 4 iunie 2019 05:51:10
Problema Subsecventa de suma maxima Scor 95
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.71 kb
#include <fstream>
using namespace std;
ifstream fin("ssm.in");
ofstream fout("ssm.out");
const int nmax = 6000005;
int v[nmax], n, x, y, maxim = -1,copie;
long long int s;
bool ok;
int main()
{
    fin >> n;
    for(int i = 1; i <= n; ++i)
        fin >> v[i];
    ok = true;
    for(int i = 1; i <= n; ++i)
    {
        s += v[i];
         if(ok)
        {
                x = i;
                ok = false;
        }
        if(s > maxim)
        {
            maxim = s;
            y = i;
            copie = x;

        }
        if(s < 0)
        {
            ok = true;
            s = 0;
        }
    }
    fout << maxim << " " << copie << " " << y << "\n";
    return 0;
}