Cod sursa(job #3238604)
| Utilizator | Data | 28 iulie 2024 11:20:11 | |
|---|---|---|---|
| Problema | Deque | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.57 kb |
#include<fstream>
#include<deque>
using namespace std;
ifstream in("deque.in"); ofstream out("deque.out");
deque <int> coada;
int v[5000005];
int main (){
int n, k;
in >> n >> k;
long long s = 0;
for(int i = 1; i <= n; i++){
in >> v[i];
while(!coada.empty() && v[i] < v[coada.back()]) coada.pop_back();
coada.push_back(i);
if(i >= k){
s += v[coada.front()];
if(!coada.empty() && i - coada.front() + 1 >= k) coada.pop_front();
}
}
out << s;
return 0;
}
