Pagini recente » Cod sursa (job #2392882) | Cod sursa (job #2393207) | Cod sursa (job #2330267) | Cod sursa (job #2788036) | Cod sursa (job #2329817)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("deque.in");
ofstream fout("deque.out");
long long n,k,v[5000001],i,suma,minim,x,j;
int main()
{
fin>>n>>k;
minim=99999999999999999;
for(i=1;i<=k;i++)
{
fin>>v[i];
if(v[i]<minim)
minim=v[i];
}
suma=minim;
for(i=1;i<=n-k;i++)
{
fin>>x;
if(minim==v[1])
{
minim=99999999999;
for(j=2;j<=k;j++)
if(v[j]<minim)
minim=v[j];
if(x<minim)
minim=x;
}
else
minim=min(minim,x);
for(j=2;j<=k;j++)
v[j-1]=v[j];
v[k]=x;
suma+=minim;
}
fout<<suma;
return 0;
}