Cod sursa(job #3218453)

Utilizator Ics.maker09Iancu Cezar-Stefan Ics.maker09 Data 27 martie 2024 11:25:58
Problema Deque Scor 25
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.42 kb
#include <bits/stdc++.h>

using namespace std;
ifstream f("deque.in");
ofstream g("deque.out");
deque <int> st;
int n,k,x,v[5000005],S,i;
int main()
{
    f >>n >>k;
    for(i=1;i<=n;i++)
    {
        f>>v[i];
        while(!st.empty() && st.back()<=i-k)st.pop_back();
        while(!st.empty() && v[i]<v[st.front()])st.pop_front();
        st.push_front(i);
        if(i>=k)S+=v[st.back()];
    }
    g<<S;
}