Cod sursa(job #2028177)

Utilizator StefanManolacheManolache Stefan StefanManolache Data 27 septembrie 2017 12:14:57
Problema Subsecventa de suma maxima Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.67 kb
#include <cstdio>
#include <climits>
#include <algorithm>

FILE *fin = fopen("ssm.in", "r");
FILE *fout = fopen("ssm.out", "w");

#define maxn 6000000
#define ll long long




int main() {
    ll n, maxx = LLONG_MIN, best, stc = 1, st, dr;
    fscanf (fin, "%lld", &n);
    fscanf(fin, "%lld", &best);
    for (ll i = 2; i <= n; i++) {
        ll t;
        fscanf (fin, "%lld", &t);
        ll k = best + t;
        best = std::max(best + t, t);
        if (best != k) {
            stc = i;
        }
        if (best > maxx) {
            maxx = best;
            st = stc;
            dr = i;
        }
    }
    fprintf(fout, "%lld %lld %lld ", maxx, st,  dr);
    return 0;
}