Cod sursa(job #2209666)

Utilizator AgacheGabrielAgache Gabriel AgacheGabriel Data 4 iunie 2018 01:17:21
Problema Subsecventa de suma maxima Scor 85
Compilator cpp Status done
Runda Arhiva educationala Marime 0.62 kb
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;

ifstream fin("ssm.in");
ofstream fout("ssm.out");

//int a[60000001];
//int dp[60000001];

int best,d,curent,x,N,jmax,imax ;

int maxi(int a,int b)
{
    return a>b ? a:b;
}

int main()
{
    fin>>N>>x;
    best = x;
    curent = x;
    d = x;
    imax = jmax = 1;
    for (int i=2;i<=N;i++)
    {
        fin>>x;
        if (x > d+x) imax = i;
        d = maxi(x,d+x);
        if (d>best)
        {
            best = d;
            jmax = i;
        }
    }
    fout<<best<<' '<<imax<<' '<<jmax;
    return 0;
}