Cod sursa(job #2673431)

Utilizator Iustin01Isciuc Iustin - Constantin Iustin01 Data 16 noiembrie 2020 19:41:07
Problema Subsecventa de suma maxima Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.46 kb
#include <bits/stdc++.h>
using namespace std;

ifstream in("ssm.in");
ofstream out("ssm.out");

long long int n, smax = -(2 * (1 << 30)), imax, jmax, s, x, st;
bool g = false;
int main(){
    in>>n;
    out<<smax<<"\n";
    for(int i = 1; i <= n; i++){
        in>>x;
        s += x;
        if(smax < s)
                smax = s, imax = st, jmax = i;
        else if(s < 0)
             s = 0, st = i + 1
    }
    out<<smax<<" "<<imax<<" "<<jmax;
}