Cod sursa(job #2983055)

Utilizator TheEpicWipedCreaVlad Chirita Alexandru TheEpicWipedCrea Data 21 februarie 2023 15:14:14
Problema Subsecventa de suma maxima Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.48 kb
#include <bits/stdc++.h>

using namespace std;
ifstream in  ("ssm.in");
ofstream out("ssm.out");

int main(){
    int n;
    in>>n;
    int smax=-2000000000;
    int s=0,x;
    int posi=1,posst=1,posdr=1,i;
    for(i=1;i<=n;i++){
        if(s<0){
            s=0;
            posi=i;
        }
        in>>x;
        s+=x;
        if(s>smax){
            smax=s;
            posst=posi;
            posdr=i;
        }
    }
    out<<smax<<" "<<posst<<" "<<posdr;
}