Mai intai trebuie sa te autentifici.

Cod sursa(job #3239487)

Utilizator Victor321321Victor Casandra Victor321321 Data 5 august 2024 20:35:12
Problema Secventa 2 Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.46 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin("secv2.in");
ofstream fout("secv2.out");

long long n, s, k;

int main()
{
    long long st, dr, Smax=-2000000000, S=-1, sttemp, i;
    fin>>n>>k;
    for(i=1; i<=n ; i++)
    {
        fin>>s;
        if(S<0)
            S=0, sttemp=i;
        S+=s;
        if(S>Smax && i-sttemp+1>=k)
            Smax=S, st=sttemp, dr=i;
    }
    fout<<st<<" "<<dr<<" "<<Smax;
    return 0;
}