Cod sursa(job #904085)
| Utilizator | Data | 3 martie 2013 18:35:25 | |
|---|---|---|---|
| Problema | Deque | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.51 kb |
#include<cstdio>
#include<deque>
using namespace std;
int v[5000005];
int main()
{
freopen("deque.in","r",stdin);freopen("deque.out","w",stdout);
deque<int>d;long long s=0;int n,k,a,i,j;
scanf("%d%d",&n,&k);
for(i=1;i<=n;++i)
{
scanf("%d",&v[i]);
while(!d.empty()&&v[i]<=v[d.back()])
d.pop_back();
d.push_back(i);
if(d.front()==i-k)
d.pop_front();
if(i>=k)
s+=v[d.front()];
}
printf("%lld",s);
}
