//It’s never too late to become what you might have been.... #include #include using namespace std; #define ll long long int #define inf 1000000000000000 #define mod 1000000007 #define pb push_back #define mp make_pair #define all(v) v.begin(),v.end() #define S second #define F first #define boost1 ios::sync_with_stdio(false); #define boost2 cin.tie(0); #define mem(a,val) memset(a,val,sizeof a) #define endl "\n" #define maxn 100001 ll a[maxn],dp[maxn],tree[4*maxn]; void update(ll node,ll a,ll b,ll ind,ll val) { if(a>b || a>ind || bb || a>r || b=l && b<=r) return tree[node]; ll mid=(a+b)/2; return min(query(2*node,a,mid,l,r),query(2*node+1,mid+1,b,l,r)); } int main() { boost1;boost2; ll i,j,n,k,x,y; cin>>n>>k; for(i=0;i<4*maxn;i++) tree[i]=inf; for(i=1;i<=n;i++) cin>>a[i]; for(i=0;i<=n;i++) dp[i]=inf; dp[0]=0; update(1,0,n,0,dp[0]); dp[1]=a[1]; update(1,0,n,1,dp[1]); for(i=2;i<=n;i++) { for(j=max(1LL,i-k);j<=i;j++) dp[i]=min(dp[i],a[j]+query(1,0,n,max(0LL,j-k-1),j-1)); update(1,0,n,i,dp[i]); } //cout<