Cod sursa(job #2951166)

Utilizator Cristi0Barbulescu Cristian Cristi0 Data 5 decembrie 2022 16:23:47
Problema Subsecventa de suma maxima Scor 90
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");
int n[6000005], bonga[6000005], y, smax = 0, st, dr;

int main()
{
    fin >> y;
    fin >> n[1];
    bonga[1] = n[1];
    for(int i = 2; i <= y; i++){
        fin >> n[i];
        bonga[i] = n[i];
    }
    for(int i =1 ;i <=y; i++){
        if(bonga[i] < n[i] + bonga[i - 1]){
            bonga[i] = bonga[i - 1] + n[i];
        }
        if(smax < bonga[i]){
            smax = bonga[i];
            dr = i;
        }
    }
    for(int i = dr; i >= 1; i--){
        if(bonga[i] <= 0){
            st = i;
            break;
        }
    }
    fout << smax << " " << st + 1 << " " << dr;
    return 0;
}