Cod sursa(job #2203380)

Utilizator IustinPetrariuIustinian Petrariu IustinPetrariu Data 12 mai 2018 09:20:19
Problema Secventa 2 Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.61 kb
#include <iostream>
#include <fstream>
#define NMAX 50001

using namespace std;
ifstream fin("secv2.in");
ofstream fout("secv2.out");
int N,K,Best[NMAX],a[NMAX],BestSum,smax,x,inc,sf,s,i;
int main()
{
    fin>>N>>K;
      i = 1;
        for(int j = 1; j <= N; j++)
        {
            fin>>x;
            s+=x;
            if(s>smax)
            {
                smax=s;
                inc=i;
                sf=j;
            }
            if(s<0)
            {
                s=0;
                i=j+1;
            }

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