#include <bits/stdc++.h>
using namespace std;
int state[(int)(1e6) + 5];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n, m;
  cin >> n >> m;
  vector<long long> a(n);
  vector<long long> ans(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a.begin(), a.end());
  long long sum = 0, days = 1;
  for (int k = 0; k < n; k++) {
    sum += a[k];
    ans[k] = sum;
    if (k >= m) ans[k] += ans[k - m];
    cout << ans[k] << " ";
  }
  cout << '\n';
  return 0;
}
