Cod sursa(job #3167224)

Utilizator Manolea_Teodor_StefanManolea Teodor Stefan Manolea_Teodor_Stefan Data 10 noiembrie 2023 13:22:48
Problema Subsecventa de suma maxima Scor 95
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.72 kb
#include <bits/stdc++.h>

using namespace std;
ifstream fin("ssm.in");
ofstream fout("ssm.out");
struct answer{
    long long value;
    int left;
    int right;
    friend ostream& operator<<(ostream& os, answer& ans){
        os<<ans.value<<' '<<ans.left<<' '<<ans.right;
        return os;
    }
} ans;

int n,x;

vector<int> s;


int main()
{
    fin>>n;
    fin>>x;
    s.push_back(x);
    ans = {x, 1, 1};
    int left;
    for(int i = 2; i<=n; i++){
        fin>>x;
        if(s.back() + x > x)
            s.push_back(s.back() + x);
        else
            left = i, s.push_back(x);
        if(s.back() > ans.value)
            ans = {s.back(), left, i};
    }
    fout<<ans;
    return 0;
}