Cod sursa(job #240662)
| Utilizator | Data | 8 ianuarie 2009 08:38:32 | |
|---|---|---|---|
| Problema | Deque | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.47 kb |
#include <stdio.h>
struct stiva {long m;long p;};
long n,k,i,p,q,a;
long long sol;
stiva st[5000002];
int main(){
freopen("deque.in","r",stdin);
freopen("deque.out","w",stdout);
scanf("%ld %ld",&n,&k);
p=1;q=0;
for (i=1;i<=n;++i){
scanf("%ld",&a);
while (a<st[q].m&&q>=p)q--;
st[++q].m=a;
st[q].p=i;
while (i-st[p].p+1>k)p++;
if (i>=k)sol+=st[p].m;
}
printf("%lld\n",sol);
return 0;
}
