Pagini recente » Rating Clipa Stefan (clipastefan) | Rating Lascu Tudor Andrei (tudor32) | Cod sursa (job #1582258) | Cod sursa (job #1388228) | Cod sursa (job #2731756)
#include <iostream>
#include <fstream>
using namespace std;
long N,K,i,st=0,dr=-1,suma=0,v[5000001],c[5000001];
int main(){
ifstream f("deque.in");
ofstream g("deque.out");
f>>N>>K;
for (i=0;i<N;i++) f>>v[i];
for (i=0;i<N;i++)
{
while (st<=dr && v[i]<=v[c[dr]])
dr--;
dr++;
c[dr]=i;
if (c[st]==i-K) st++;
if (i+1>=K) suma=suma+v[c[st]];
}
g<<suma;
f.close();
g.close();
return 0;
}