Cod sursa(job #1765703)

Utilizator nurof3nCioc Alex-Andrei nurof3n Data 26 septembrie 2016 22:09:05
Problema Subsecventa de suma maxima Scor 95
Compilator cpp Status done
Runda Arhiva educationala Marime 0.53 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("ssm.in");
ofstream g("ssm.out");
const int MAXN=6000001;
int n,best[MAXN],smax=-200000000,x,in,sf,inmax;
int main()
{
    f>>n;
    for(int i=1;i<=n;i++)
    {
        f>>x;
        best[i]=x;
        if(best[i]<best[i-1]+x)
            best[i]=best[i-1]+x;
        else in=i;
        if(smax<best[i])
        {
            smax=best[i];
            inmax=in;
            sf=i;
        }
    }
    g<<smax<<' '<<inmax<<' '<<sf;
    return 0;
}