Cod sursa(job #3345365)

Utilizator viktorunixMurgu Andrei viktorunix Data 9 martie 2026 13:25:25
Problema Subsecventa de suma maxima Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.93 kb
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
#include <fstream>
using namespace std;
int main()
{
    ifstream in("ssm.in");
    ofstream out("ssm.out");
    int bestsum = -999999999, sum = 0, beg, end, idx;
    int n, current;
    in >> n;
    for(int i = 1; i <= n; i++){
        in >> current;
        if(sum < 0){
            sum = current;
            idx = i;
        }
        else{
            sum += current;
            
        }
        if(bestsum < sum){
            bestsum = sum;
            beg = idx;
            end = i;
        }
    }
    out << bestsum << " " << beg << " " << end;
    return 0;
}