Cod sursa(job #3039369)
| Utilizator | Data | 28 martie 2023 14:22:40 | |
|---|---|---|---|
| Problema | Deque | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.61 kb |
#include <bits/stdc++.h>
using namespace std;
deque<int> dechiu;
long long int n,v[5000005],k,sol;
int main()
{
ifstream cin("deque.in");
ofstream cout("deque.out");
cin >> n >> k;
for(int i = 1; i <= n; i++){
cin >> v[i];
}
for(int i = 1; i <= n; i++){
while(!dechiu.empty() && a[dechiu.back()] >= v[i]){
dechiu.pop_back();
}
dechiu.push_back(i);
while(i-dechiu.front()+1 > k){
dechiu.pop_front();
}
if(i >= k){
sol += v[dechiu.front()];
}
}
cout << sol;
}
