Cod sursa(job #2936951)
Utilizator | Petre Ionut PetreIonut69420 | Data | 9 noiembrie 2022 18:15:34 |
---|---|---|---|
Problema | Deque | Scor | 0 |
Compilator | cpp-64 | Status | done |
Runda | cnilc1_2-dq | Marime | 0.5 kb |
#include <bits/stdc++.h>
using namespace std;
long long int n , i , k , x , a[5000005] , p , u , s;
deque <long long int> q;
ifstream f("deque.in");
ofstream g("deque.out");
int main()
{
f >> n >> k;
for(i=1;i<=n;i++) f >> a[i];
for(i=1;i<=n;i++){
p++;
while(!q.empty() && a[i]<=a[q.back()]){
q.pop_back();
}
q.push_back(i);
if(i>=k) while(!q.empty() && i-q.front()+1>k) q.pop_front() , s+=a[q.front()];
}
g << s;
}