Cod sursa(job #2720546)
| Utilizator | Data | 10 martie 2021 22:41:03 | |
|---|---|---|---|
| Problema | Deque | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.51 kb |
#include <fstream>
#include <deque>
#define ll long long
std::ifstream fin("deque.in");
std::ofstream fout("deque.out");
std::deque<std::pair<int, int>>dq;
int main() {
std::ios::sync_with_stdio(false);
fin.tie(0);
fout.tie(0);
ll n, c, k, s = 0;
fin>>n>>k;
for(int i=0;i<n;i++) {
fin>>c;
while(!dq.empty() and dq.front().second<=i-k) dq.pop_front();
while(!dq.empty() and dq.back().first>=c) dq.pop_back();
dq.push_back({c, i});
if(i>=k-1) s+=dq.front().first;
}
fout<<s;
}