Cod sursa(job #3239024)

Utilizator Gabriel_DaescuDaescu Gabriel Florin Gabriel_Daescu Data 1 august 2024 14:43:05
Problema Secventa 2 Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.47 kb
#include <fstream>
using namespace std;
ifstream  fin("secv2.in");
ofstream fout("secv2.out");
int N,K,x,i,st,dr,S,Smax;

int main()
{
    fin>>N>>K;

    S=-1;
    Smax=0;
    for(i=1; i<=N; i++)
    {
        fin>>x;

        if(S<0)
        {
            S=0;
            st=i;
        }

        S=S+x;

        if(S>Smax && i-st+1>=K)
        {
            Smax=S;
            dr=i;
        }
    }

    fout<< st << " " << dr << " " << Smax;
}