#include <bits/stdc++.h>
using namespace std;
long long inf = 1e16;
long long power(long long x, long long n, long long mod) {
  long long res = 1;
  x %= mod;
  while (n) {
    if (n & 1) res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}
long long dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, m;
  cin >> n >> m;
  long long a[n];
  for (long long i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  for (long long i = 1; i < n; i++) a[i] = a[i] + a[i - 1];
  for (long long i = 0; i < n; i++) {
    if (i >= m) a[i] += a[i - m];
    cout << a[i] << " ";
  }
  cout << endl;
  return 0;
}
