Cod sursa(job #2322165)

Utilizator marius0072scarlat marius stefan marius0072 Data 17 ianuarie 2019 14:40:55
Problema Subsecventa de suma maxima Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.73 kb
#include <fstream>
using namespace std;
ifstream cin("ssm.in");
ofstream cout("ssm.out");
int main()
{
    int n, maxim, maxG, dr, st, drG, stG;
    cin >> n;
    int v[n];
    for (int i = 0; i < n; ++i)
        cin >> v[i];
    maxim = maxG = v[0];
    dr = st = 0;
    for (int i = 1; i < n; ++i)
    {
        if (v[i] > maxim + v[i])
        {
            st = dr = i;
            maxim = v[i];
        }
        else
        {
            maxim = v[i] + maxim;
            st++;
        }
        
        if (maxim >= maxG)
            {
                maxG = maxim;
                stG = st;
                drG = dr;
            }
    }
    cout << maxG << " " << drG + 1<< " " << stG + 1;
    return 0;
}