Pagini recente » Cod sursa (job #3230901) | Cod sursa (job #1957230) | Cod sursa (job #1955608) | Cod sursa (job #2588509) | Cod sursa (job #3275669)
#include <fstream>
using namespace std;
ifstream cin ("deque.in");
ofstream cout ("deque.out");
const int NMAX=5000001;
int v[NMAX],vv[NMAX];
long long s,n,k,inc,sf;
int main()
{
inc=sf=1;
cin>>n>>k;
for(int i=1;i<=n;++i){
cin>>v[i];
while(sf>=inc && v[vv[sf]]>=v[i] )
--sf;
++sf;
vv[sf]=i;
if(i>=k){
if(i-vv[inc]+1>k)
inc++;
s+=v[vv[inc]];
}
}
cout<<s;
return 0;
}