Cod sursa(job #2369516)
| Utilizator | Data | 6 martie 2019 00:09:30 | |
|---|---|---|---|
| Problema | Deque | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.46 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream in("deque.in");
ofstream out("deque.out");
deque<pair<long long,int>> q;
long long n,k,x,y,s;
int main()
{
in>>n>>k;
for(int i=1;i<=n;i++)
{
in>>x;
if(!q.empty()&&q.front().second<i-k+1) q.pop_front();
while(!q.empty()&&x<=q.back().first) q.pop_back();
q.push_back({x,i});
if(i>=k) s+=q.front().first;
}
out<<s;
return 0;
}
