#include <bits/stdc++.h>
using namespace std;
long long x, y, sum = 0, a[100004], dp[100004], answer;
int main() {
  cin >> x >> y;
  for (int i = 0; i < x; i++) cin >> a[i];
  sort(a, a + x);
  dp[0] = a[0];
  for (int i = 1; i < x; i++) {
    dp[i] = dp[i - 1] + a[i];
  }
  for (int i = x - 1; i >= y; i -= y) {
    if ((dp[i] - dp[i - y]) > 0) {
      sum += dp[i] - dp[i - y];
    } else
      break;
  }
  cout << sum;
}
