Cod sursa(job #2802291)
| Utilizator | Data | 17 noiembrie 2021 21:15:52 | |
|---|---|---|---|
| Problema | Deque | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.61 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream in("deque.in");
ofstream out("deque.out");
struct nr
{
int v,p;
};
long long s;
deque<nr>a;
int main()
{
int n,k;
in >> n >> k;
for (int i = 1; i <= n; i++)
{
int x;
in >> x;
while (!a.empty() and x <= a.front().v)
a.pop_front();
nr aux;
aux.v = x;
aux.p = i;
a.push_front(aux);
while (a.size() != 0 and a.back().p <= i - k)
a.pop_back();
if (i >= k)
s += a.back().v;
}
out << s;
return 0;
}
