Cod sursa(job #2120941)

Utilizator Steve_ITStefan Ursache Steve_IT Data 3 februarie 2018 10:01:05
Problema Subsecventa de suma maxima Scor 55
Compilator cpp Status done
Runda Arhiva educationala Marime 0.36 kb
#include <fstream>
using namespace std;
ifstream f("ssm.in");
ofstream g("ssm.out");
long long n, i, a, sum, smax, pi, ps;
int main () {
    f>>n>>a; sum = smax = a; pi = ps = 1;
    for (i=2; i<=n; i++) {
        f>>a;
        sum+=a;
        if(sum>smax) smax = sum, ps = i;
        if(sum<0) sum = a, pi = i;
    }
    g<<smax<<' '<<pi<<' '<<ps;
    return 0;
}