#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define popcount __builtin_popcount using namespace std; using ll=long long; typedef pair P; int main() { int n, k; cin>>n>>k; ll a[200020]; for(int i=0; i>a[i]; } priority_queue que; ll ans=a[k-1]; ll s=0; for(int i=1; (i+1)*k-1a[j]){ jmn=j; } } for(int j=i*k-1; j<(i+1)*k-1; j++){ if(j==jmn) continue; que.push(a[j]); s+=a[j]; while(que.size()>i-1){ ll x=que.top(); que.pop(); s-=x; } } que.push(a[jmn]); s+=a[jmn]; ans=min(ans, s+a[(i+1)*k-1]); } cout<