#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n, m;
  cin >> n >> m;
  long long arr[n];
  for (long long i = 0; i < n; i++) cin >> arr[i];
  sort(arr, arr + n);
  vector<long long> ans(n);
  long long cursum = 0;
  for (long long i = 0; i < n; i++) {
    cursum += arr[i];
    ans[i] = cursum;
    if (i >= m) {
      ans[i] += ans[i - m];
    }
    cout << ans[i] << " ";
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return 0;
}
