Pagini recente » Cod sursa (job #2292361) | Cod sursa (job #1538901) | Cod sursa (job #2948096) | Cod sursa (job #14130) | Cod sursa (job #2615439)
#include <bits/stdc++.h>
#define DAU ios::sync_with_stdio(false); fin.tie(0); fout.tie(0);
#define PLEC fin.close(); fout.close(); return 0;
using namespace std;
const string problem("deque");
ifstream fin(problem + ".in");
ofstream fout(problem + ".out");
deque<pair<int, int>> dq;
int n, k, x;
long long res;
int main() {
DAU
fin >> n >> k;
for (int i = 1; i <= n; ++i) {
fin >> x;
while (!dq.empty() && i - dq.back().second >= k)
dq.pop_back();
while (!dq.empty() && x < dq.front().first)
dq.pop_front();
dq.emplace_front(x, i);
if (i >= k)
res += dq.back().first;
}
fout << res;
PLEC
}