Cod sursa(job #2585583)

Utilizator Cosmin1234Creanga Cosmin Andrei Cosmin1234 Data 19 martie 2020 10:41:05
Problema Subsecventa de suma maxima Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.37 kb
#include <iostream>
#include <fstream>

using namespace std;

const int INF=1000000000;
ifstream in ("ssm.in");
ofstream out ("ssm.out");

int main()
{
    int n, sc=-INF,  smax=-INF, x;
    in>>n;
    for(int i=0;i<n;i++)
    {
        in>>x;
        if(sc<0)
            sc=0;
        sc+=x;
        if(sc>smax)
            smax=sc;
    }
    out<<smax;
}