Cod sursa(job #2586251)

Utilizator shirokumaShiro Kuma shirokuma Data 20 martie 2020 10:28:40
Problema Secventa 2 Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.63 kb
#include <bits/stdc++.h>
#define MAX 50000
using namespace std;
ifstream fin("secv2.in");
ofstream fout("secv2.out");
//int v[MAX+5];
int main()
{
    int n,k,i,x, lcrt=0, start=0, lmax=0;
    long long s=0,smax=INT_MIN;
    fin>>n>>k;
    for(i=1;i<=n;i++)
    {
        fin>>x;
        s+=x;
        lcrt++;
        if(s>smax && lcrt>=k)
        {
            smax=s;
            start=i-lcrt+1;
            lmax=lcrt;
        }
        if(s<0)
        {
            s=0;
            lcrt=0;
        }
    }
    fout<<start<<" "<<start+lmax-1<<" "<<smax;
    fin.close();
    fout.close();
    return 0;
}