Cod sursa(job #2999785)
| Utilizator | Data | 11 martie 2023 14:51:16 | |
|---|---|---|---|
| Problema | Deque | Scor | 15 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.46 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("deque.in");
ofstream fout("deque.out");
deque<pair<long long,int>>Q;
int main()
{
int n,i,k;
long long s=0,x;
fin>>n>>k;
for(i=1; i<=n; i++)
{
fin>>x;
while(Q.empty()==0 && Q.front().first>x)Q.pop_back();
Q.push_back(make_pair(x,i));
while(Q.front().second<i-k+1)Q.pop_front();
if(i>=k)s+=Q.front().first;
}
fout<<s;
}
