Cod sursa(job #1493626)

Utilizator BaweeLazar Vlad Bawee Data 29 septembrie 2015 18:39:38
Problema Subsecventa de suma maxima Scor 55
Compilator cpp Status done
Runda Arhiva educationala Marime 0.63 kb
#include <iostream>
#include <cstdio>

using namespace std;

int n,x[6000005];

int main()
{
    freopen("ssm.in","r",stdin);
    freopen("ssm.out","w",stdout);

    cin >> n;

    for(int i = 1; i <= n; i++) cin >> x[i];

    int first = 1,last,best = -int(2e9);
    long long S = 0;

    for(int i = 1; i <= n; i++){
            S += x[i];
        if(S > best)
        {
            best = S;
            last = i;
        }
        if(S < 0)
        {
            S = 0;
            first = i + 1;
            last = 0;
        }
    }

    cout << best << " " << first << " " << last;
    return 0;
}