Cod sursa(job #2543991)
| Utilizator | Data | 11 februarie 2020 18:00:49 | |
|---|---|---|---|
| Problema | Deque | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.58 kb |
#include <fstream>
#include <deque>
std::ifstream f("deque.in");
std::ofstream g("deque.out");
long long n,k,x,sol;
std::deque< std::pair<long long,int> >d;
int main(){
f >> n >> k >> x;
d.push_back({x,1});
for(int i = 2;i <= n;++i){
f >> x;
while(!d.empty() && x <= d.back().first)
d.pop_back();
d.push_back({x,i});
if(i - d.front().second >= k)
d.pop_front();
if(i >= k)
sol += d.front().first;
}
g << sol;
return 0;
}
