#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  long long k[n];
  for (int i = 0; i < n; i++) cin >> k[i];
  sort(k, k + n);
  long long psum[n];
  psum[0] = k[0];
  for (int i = 1; i < n; i++) psum[i] = k[i] + psum[i - 1];
  long long ans[n];
  ans[0] = psum[0];
  cout << ans[0] << " ";
  for (int i = 1; i < n; i++) {
    ans[i] = psum[i];
    if (i + 1 - m > 0) ans[i] += ans[i + 1 - m - 1];
    cout << ans[i] << " ";
  }
}
