Cod sursa(job #2495610)

Utilizator RedXtreme45Badu Catalin RedXtreme45 Data 19 noiembrie 2019 18:08:10
Problema Subsecventa de suma maxima Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.72 kb
#include <fstream>
#define INF 0x3f3f3f3f
using namespace std;
ifstream fin("ssm.in");
ofstream fout("ssm.out");
int n,a,i,S=0,inc=1,sf=1;
int max1=-INF;
int main()
{
    fin>>n;
    int p=1,u=0;
    for (i=1;i<=n;i++)
    {
        fin>>a;
        S+=a;
        if (S>=0)
        {
            u++;
            if (S>max1)
            {
                max1=S;
                inc=p;
                sf=u;
            }
        }
        else
        {
            if (S>max1)
            {
                max1=S;
                inc=p;
                sf=u+1;
            }
            p=i+1;
            u=i;
            S=0;

        }
    }
    fout<<max1<<" "<<inc<<" "<<sf;
    return 0;
}