Cod sursa(job #1976574)

Utilizator stefdascalescuStefan Dascalescu stefdascalescu Data 3 mai 2017 19:33:04
Problema Secventa 2 Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.69 kb
#include<bits/stdc++.h>
using namespace std;
ifstream f("secv2.in");
ofstream g("secv2.out");
long long n,k,x,s;
long long smax,st,dr;
deque<long long>v;
int main()
{
    f>>n>>k;
    for(int i=1;i<=n;++i)
    {
        f>>x;
        if(v.size()<k){
            v.push_back(x);
            s+=x;
        }
        else
        {
            if(s>smax)
            {
                smax=s;
                st=i-v.size()+1;
                dr=i-1;
            }
            if(s+x>=s-v[0]){
                v.pop_front();
                s-=v[0];
            }
            v.push_back(x);
            s+=x;
        }
    }
    g<<st<<" "<<dr<<" "<<smax<<'\n';
    return 0;
}