#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 10;
const long long M = 1e7 + 1000;
const long long mod = 1e9 + 7;
const long long INF = 1e18;
const long long inf = -1e18;
bool isprime(long long x) {
  if (x == 1) return false;
  long long y = sqrt(x);
  for (long long i = 2; i <= y; i++) {
    if (x % i == 0) {
      return false;
    }
  }
  return true;
}
long long bin_pow(long long a, long long b) {
  if (b == 0) return 1;
  if (b == 1) return a % mod;
  if (a == 0) return 0;
  if (a == 1) return a % mod;
  if (b % 2 == 0) {
    long long pw = bin_pow(a, b / 2) % mod;
    return (pw * pw) % mod;
  } else {
    return (bin_pow(a, b - 1) * a) % mod;
  }
}
const long double pi = acos(-1);
long long n, m;
deque<long long> dk;
long long a[2 * N], us[2 * N], b[2 * N], ans[2 * N];
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  int k = 1;
  for (int i = 1; i <= n; i++) {
    us[i] = k;
    if (i % m == 0) {
      k++;
    }
  }
  reverse(us + 1, us + n + 1);
  sort(a + 1, a + n + 1);
  for (int i = n; i >= n - m + 1; i--) {
    long long s = 0;
    for (int j = i; j >= 1; j -= m) {
      s += a[j];
    }
    dk.push_back(s);
  }
  long long s = 0;
  for (int i = n; i >= 1; i--) {
    s += us[i] * a[i];
  }
  int j = 0;
  long long s1 = 0;
  for (int i = n; i >= 1; i--) {
    ans[i] = s;
    s -= dk[j] - b[j];
    b[j] += a[i];
    if ((j + 1) % m == 0) {
      j = -1;
    }
    j++;
  }
  for (int i = 1; i <= n; i++) {
    cout << ans[i] << " ";
  }
}
