Cod sursa(job #3156305)

Utilizator CastielGurita Adrian Castiel Data 11 octombrie 2023 10:29:37
Problema Subsecventa de suma maxima Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.17 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>
#include <cmath>
using namespace std;
ifstream fin("ssm.in");
ofstream fout("ssm.out");
int n,v[6000002],a,best[6000002],u,p;
int main()
{
    fin>>n;
    for(int i=1;i<=n;i++)
    {
        fin>>v[i];
    }
    best[1]=v[1];
    a=v[1];
    for(int i=2;i<=n;i++)
    {
        best[i]=max(best[i-1]+v[i],v[i]);
        a=max(a,best[i]);
    }
    for(int i=1;i<=n;i++)
    {
        if(best[i]==a)
        {
            int j=i;
            u=i;
            while(j>0)
            {
                j--;
                p=j;
                if(best[j]<0)
                {
                    break;
                }
            }
            break;
        }
    }
    fout<<a<<" "<<p+1<<" "<<u;
    fin.close();
    fout.close();
    return 0;
}