Cod sursa(job #2980915)

Utilizator NarcisMMic Narcis NarcisM Data 16 februarie 2023 22:00:40
Problema Subsecventa de suma maxima Scor 85
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.46 kb
#include <bits/stdc++.h>
using namespace std;
ifstream fin("ssm.in");
ofstream fout("ssm.out");
int n, v[6000001], smax = -2e9, p, q, s;
int main(){
    fin >> n;
    for(int i = 1; i <= n; i++)
        fin >> v[i];
    for(int i = 1; i <= n; i++){
        if(s < 0)
            s = v[i], p = i;
        else
            s += v[i];
        if(smax < s)
            smax = s, q = i;
    }
    fout << smax << ' ' << p << ' ' << q;
    return 0;
}