Cod sursa(job #3159318)

Utilizator Alexandru_AugustinPopescu Alexandru Alexandru_Augustin Data 21 octombrie 2023 09:31:22
Problema Subsecventa de suma maxima Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.67 kb
#include <fstream>
using namespace std;
ifstream fin("ssm.in");
ofstream fout("ssm.out");
typedef long long ll;

int main(){
    int n;
    ll x;
    fin >> n;
    ll best = 0;
    ll sumMax = -5000000000;
    int indSt = 0, indDr = 0;
    int lung = 0;
    for(int i = 1; i <= n; i++){
        fin >> x;
        if(x + best >= x){
            best += x;
            lung++;
        }
        else{
            best = x;
            lung = 1;
        }
        if(best > sumMax){
            sumMax = best;
            indDr = i;
            indSt = indDr - lung + 1;
        }
    }
    fout << sumMax << " " << indSt << " " << indDr;
    return 0;
}