#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, m;
  cin >> n >> m;
  vector<long long int> v;
  for (int i = 0; i < n; i++) {
    long long int x;
    cin >> x;
    v.push_back(x);
  }
  sort(v.begin(), v.end());
  vector<pair<long long int, int>> minsums;
  map<int, int> vis;
  for (int i = n - 1; i >= 0; i--) {
    if (vis[i] == 1) break;
    long long int ans = 0;
    int k = 0;
    for (int j = i; j >= 0; j = j - m) {
      vis[j] = 1;
      ans = ans + v[j];
      k = k + 1;
    }
    minsums.push_back(make_pair(ans, k));
  }
  vector<long long int> ans(n);
  long long int anss = 0;
  int k = 1;
  int gg = 0;
  for (int i = n - 1; i >= 0; i--) {
    anss = anss + v[i] * k;
    gg++;
    if (gg == m) {
      gg = 0;
      k++;
    }
  }
  ans[n - 1] = anss;
  int cnt = 0;
  int cnt2 = n - 1;
  for (int i = n - 2; i >= 0; i--) {
    anss = anss - minsums[cnt].first;
    minsums[cnt].first = minsums[cnt].first - v[cnt2];
    cnt = (cnt + 1) % ((int)(minsums.size()));
    cnt2--;
    ans[i] = anss;
  }
  for (int i = 0; i < n; i++) {
    cout << ans[i] << " ";
  }
}
