Cod sursa(job #3233712)
Utilizator | Data | 4 iunie 2024 17:24:47 | |
---|---|---|---|
Problema | Deque | Scor | 25 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.56 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("deque.in");
ofstream fout("deque.out");
int n, i, k, s, a[5000002];
deque<int> q;
int main() {
ios_base::sync_with_stdio(false);
fin.tie(nullptr);
fout.tie(nullptr);
fin >> n >> k;
for(i = 1; i <= n; i++) fin >> a[i];
for(i = 1; i <= n; i++) {
while(!q.empty() && a[q.back()] >= a[i]) q.pop_back();
q.push_back(i);
if(q.front() == i - k) q.pop_front();
if(i >= k) s += a[q.front()];
}
fout << s;
return 0;
}