#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int n, m, i, j;
  cin >> n >> m;
  vector<long long int> a(n), b(n), pre(n + 1);
  for (long long int i = 0; i < n; i++) cin >> a[i];
  sort(a.begin(), a.end());
  pre[0] = 0;
  for (i = 0; i < n; i++) pre[i + 1] = pre[i] + a[i];
  int cnt = 0;
  b[0] = a[0];
  for (i = 1; i < m; i++) b[i] += b[i - 1];
  for (i = 0; i < n; i++) {
    b[i] = pre[i + 1];
    if (i - m >= 0) b[i] += b[i - m];
  }
  for (long long int i = 0; i < n; i++) cout << b[i] << " ";
  cout << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  int T = 1;
  while (T--) {
    solve();
  }
  return 0;
}
