#include using namespace std; typedef long long ll; typedef pair P; #define REP(i,n) for(ll i=0;i0){ k=(k-1)/2; tree[k]=min(tree[2*k+1], tree[2*k+2]); } } ll query(ll a, ll b, ll k, ll l, ll r){ if(r<=a || b<=l) return INF; if(a<=l && r<=b) return tree[k]; else return min(query(a,b,2*k+1,l,(l+r)/2),query(a,b,2*k+2,(l+r)/2,r)); } int main(void){ ll i; cin.tie(0); ios_base::sync_with_stdio(false); ll K; cin >> N >> K; ll S=0; for(i=1;i<=N;i++){ cin >> a[i]; S+=a[i]; } init(); update(0,0); for(i=1;i<=N+1;i++){ ll mn=query(max(i-K,0LL),i,0,0,n); if(i==N+1){ cout << S-a[i]-mn << endl; return 0; } update(i,a[i]+mn); } return 0; }