Cod sursa(job #2639695)
| Utilizator | Data | 3 august 2020 15:40:50 | |
|---|---|---|---|
| Problema | Deque | Scor | 25 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.48 kb |
#include <bits/stdc++.h>
#define oo 5000005
using namespace std;
ifstream in("deque.in");
ofstream out("deque.out");
int n, k, sum , v[oo];
deque < int > d;
int main(){
in>>n>>k;
for(int i = 1; i <= n; i++){
in>>v[i];
while(!d.empty() && v[i] <= v[d.back()])
d.pop_back();
d.push_back(i);
if(d.front() == i - k)
d.pop_front();
if(i >= k)
sum += v[d.front()];
}
out<<sum;
}
