#include <bits/stdc++.h>
using namespace std;
long long v[200010], s[200010], n, m;
int32_t main() {
  scanf("%lli %lli", &n, &m);
  for (long long i = 0; i < n; i++) scanf("%lli", &v[i]);
  sort(v, v + n);
  memset(s, -1, sizeof(s));
  for (long long i = 0; i < n; i++) {
    if (s[i] == -1) {
      s[i] = v[i];
      for (long long j = i + m; j < n; j += m) {
        s[j] = s[j - m] + v[j];
      }
    }
  }
  long long res = 0, dia = 0;
  long long pref = 0;
  for (long long i = 0; i < n; i++) {
    res += s[i];
    printf("%lli ", res);
  }
  puts("");
  return 0;
}
