Cod sursa(job #2951163)

Utilizator Cristi0Barbulescu Cristian Cristi0 Data 5 decembrie 2022 16:22:50
Problema Subsecventa de suma maxima Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.72 kb
#include <bits/stdc++.h>

using namespace std;
ifstream cin("ssm.in");
ofstream cout("ssm.out");
int n[6000005], bonga[6000005], y, smax = 0, st, dr;

int main()
{
    cin >> y;
    cin >> n[1];
    bonga[1] = n[1];
    for(int i = 2; i <= y; i++){
        cin >> 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;
        }
    }
    cout << smax << " " << st + 1 << " " << dr;
    return 0;
}