#include <bits/stdc++.h>
using namespace std;
vector<long long int> fin, v;
long long int sm[200005];
long long int vis[200005];
int main() {
  ios_base::sync_with_stdio(false);
  long long int n, i, j, k, x, y, t, m;
  cin >> n >> m;
  for (i = 1; i <= n; i++) {
    cin >> x;
    v.push_back(x);
  }
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());
  long long int f = 1, ans = 0, top = 0;
  for (i = 0; i < n; i++) {
    top++;
    if (top > m) top = 1, f++;
    ans += f * v[i];
  }
  for (i = 0; i < n; i++) {
    if (!vis[i]) {
      long long int tmp = 0, now = 0;
      for (j = i; j < n; j += m) tmp += v[j], vis[j] = 1;
      for (j = i; j < n; j += m) {
        sm[j] = tmp - now;
        now += v[j];
      }
    }
  }
  fin.push_back(ans);
  for (i = 1; i < n; i++) {
    ans -= sm[i - 1];
    fin.push_back(ans);
  }
  reverse(fin.begin(), fin.end());
  for (i = 0; i < (long long int)fin.size(); i++) cout << fin[i] << " ";
  cout << endl;
}
