#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(time(0));
void solve() {
  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);
  long long pref[n];
  for (long long i = 0; i < n; ++i) {
    pref[i] = a[i];
    if (i - m >= 0) pref[i] += pref[i - m];
  }
  long long ans = 0;
  for (long long i = 0; i < n; ++i) {
    ans += pref[i];
    cout << ans << ' ';
  }
  cout << endl;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long t = 1;
  while (t--) {
    solve();
  }
}
