Cod sursa(job #1623169)

Utilizator crion1999Anitei cristi crion1999 Data 1 martie 2016 17:38:47
Problema Subsecventa de suma maxima Scor 40
Compilator cpp Status done
Runda Arhiva educationala Marime 0.65 kb
#include <iostream>
#include <fstream>


using namespace std;
ifstream fi("ssm.in");
ofstream fo("ssm.out");
int sp[6000000];
int main()
{
        int n,i,a,maxx=-100000,j,maxi,maxj;
        fi>>n;
        sp[0]=0;
        for(i=1;i<=n;i++)
        {
            fi>>a;
            sp[i]=sp[i-1]+a;
        }

        for(i=1;i<=n;i++)
        {
            for(j=i;j<=n;j++)
            {
                if(sp[j]-sp[i-1]>maxx)
                {
                    maxx=sp[j]-sp[i-1];
                    maxi=i;
                    maxj=j;
                }
            }
        }
        fo<<maxx<<" "<<maxi<<" "<<maxj;

}