Pagini recente » Cod sursa (job #1672479) | Cod sursa (job #933339) | Cod sursa (job #1966874) | Cod sursa (job #2799846) | Cod sursa (job #384748)
Cod sursa(job #384748)
#include <stdio.h>
long v[5000001],p[5000001];
long long s;
int main()
{
long n,k,i,c=0,j,x;
freopen("deque.in","r",stdin);
freopen("deque.out","w",stdout);
scanf("%ld%ld",&n,&k);
v[1]=10000001;
for (i=1;i<n+1;i++)
{
if (p[1]==i-k)
{
--c;
for (j=1;j<c+1;j++) {v[j]=v[j+1];p[j]=p[j+1];}
}
scanf("%ld",&x);
++c;
while ((x<v[c-1])&&(c>1))
{
--c;
}
v[c]=x;
p[c]=i;
if (i>k-1) s+=v[1];
}
printf("%lld",s);
return 0;
}