Cod sursa(job #1279262)

Utilizator PTAdrian64Pop-Tifrea Adrian PTAdrian64 Data 29 noiembrie 2014 23:46:22
Problema Subsecventa de suma maxima Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.79 kb
#include <cstdio>
#define nmax 6000020
#define ll long long
#include <algorithm>
#define inf 2e9

using namespace std;

ll a[nmax],f1,l1,s;
ll n,bstsum;

void read(){
    scanf("%lld ",&n);
    for(ll i = 1 ; i <= n ;i++)scanf("%lld ",&a[i]);
}

void solve(){
    bstsum = -inf;
    s = 0;
    ll f = 1;
    for(ll i = 1 ; i <= n ;i++){
            if(s < 0){
                s = a[i];
                f = i;
            }
            else{
                s += a[i];
            }
            if(bstsum<s){
                bstsum = s;
                f1 = f;l1 = i;
            }
    }
}

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

    printf("%lld %lld %lld \n",bstsum,f1,l1);

    return 0;
}