Cod sursa(job #2102180)

Utilizator victorv88Veltan Victor victorv88 Data 8 ianuarie 2018 15:15:00
Problema Subsecventa de suma maxima Scor 5
Compilator cpp Status done
Runda Arhiva educationala Marime 0.69 kb
#include <iostream>
#include <fstream>
using namespace std;

ifstream f("ssm.in");
ofstream g("ssm.out");

int n, x[6000005], nr=0, maxi=-(1<<31), poz1, poz2,q;
int best[6000005];

void ssm()
{
    for (int i=1; i<=n; i++)
    {
        f >> x[i];
        best[i]=max(best[i-1]+x[i],x[i]);
        if (best[i]==x[i] && best[i]>maxi)
        {
            maxi=best[i];
            poz1=i,poz2=i;
        }
        else if (best[i]>maxi)
        {
            poz2++;
        }
    }
    while (x[poz1]==0)
    {
        poz1++;
    }
    while (x[poz2]==0)
        poz2--;
    g << maxi <<' ' <<poz1 <<' ' <<poz2;
}

int main()
{
    f >> n;
    ssm();
    return 0;
}