Cod sursa(job #2028173)

Utilizator StefanManolacheManolache Stefan StefanManolache Data 27 septembrie 2017 12:11:45
Problema Subsecventa de suma maxima Scor 95
Compilator cpp Status done
Runda Arhiva educationala Marime 0.64 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);
        best = std::max(best + t, t);
        if (best == t) {
            stc = i;
        }
        if (best > maxx) {
            maxx = best;
            st = stc;
            dr = i;
        }
    }
    fprintf(fout, "%lld %lld %lld ", maxx, st,  dr);
    return 0;
}