Cod sursa(job #2203390)

Utilizator IustinPetrariuIustinian Petrariu IustinPetrariu Data 12 mai 2018 09:39:09
Problema Secventa 2 Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.73 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],start,total,finish,smax,x,s,p;
int main()
{
    fin>>N>>K;

        for(int j = 1; j <= N; j++)
        {
            fin>>x;
             if(s>=0)
                s+=x;
             else
             {
                 s=x;
                 p=j;
             }
            if(s>smax && j-p+1 >= K)
            {
                smax=s;
                start=p;
               finish=j;
            }
            total+=x;

        }
        if(K==N) fout<<"1"<<" "<<N<<" "<<total;
        else fout<<start<<" "<<finish<<" "<<smax;
    return 0;
}