#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n, m;
  cin >> n >> m;
  vector<long long> a(n);
  for (long long i = 0; i < n; i++) cin >> a[i];
  vector<long long> ans(n + 1);
  sort(a.begin(), a.end());
  long long cnt = 0, j = 0;
  vector<long long> pre(n);
  pre[0] = a[0];
  for (long long i = 1; i < n; i++) {
    pre[i] = pre[i - 1] + a[i];
  }
  long long mul = 1;
  for (long long i = 0; i < n; i++) {
    if (i < m)
      ans[i] = pre[i];
    else
      ans[i] = pre[i] + ans[i - m];
  }
  for (long long i = 0; i < n; i++) cout << ans[i] << " ";
}
