Cod sursa(job #2156593)
| Utilizator | Data | 8 martie 2018 20:39:52 | |
|---|---|---|---|
| Problema | Deque | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.45 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream f("deque.in");
ofstream g("deque.out");
int n,k,a[5000001];
long long s;
deque<int> x;
int main()
{
f>>n>>k;
for(int i=1; i<=n; ++i)f>>a[i];
for(int i=1; i<=n; ++i)
{
while(!x.empty()&&a[i] <= a[x.back()])x.pop_back();
x.push_back(i);
if(x.front()==i-k)x.pop_front();
if(i>=k)s+=a[x.front()];
}
g<<s;
return 0;
}
