Cod sursa(job #2391733)

Utilizator monaaMona Dumbravescu monaa Data 29 martie 2019 10:13:53
Problema Subsecventa de suma maxima Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.59 kb
#include <bits/stdc++.h>
using namespace std;
long long y, n, s, i, p1, p2, ct, nrmax = LLONG_MIN, pmax, x, maxx = LLONG_MIN;
int main()
{
    ifstream f("ssm.in");
    ofstream g("ssm.out");
    f >> n;
    for(i = 1; i <= n; i++)
    {
        ct++;
        f >> y;
        s = s + y;
        if(y > nrmax) nrmax = y, pmax = i;
        if(s > maxx) maxx = s, p2 = i, x = ct;
        if(s < 0) s = 0, ct = 0;
    }
    if(maxx < 0)
    {
        g << nrmax << " " << pmax << " " << pmax;
        return 0;
    }
    g << maxx << " " << p2 - x + 1 << " " << p2;
    return 0;
}