#include <bits/stdc++.h>
using namespace std;
const int inf = 1 << 30;
const long long linf = 1LL << 62;
const int mod = 1e9 + 7;
const int MAX = 5100000;
const int V = 100005;
long long dy[8] = {1, 0, -1, 0, 1, -1, 1, -1};
long long dx[8] = {0, 1, 0, -1, 1, -1, -1, 1};
const double pi = acos(-1);
template <typename T1, typename T2>
inline void chmin(T1 &a, T2 b) {
  if (a > b) a = b;
}
template <typename T1, typename T2>
inline void chmax(T1 &a, T2 b) {
  if (a < b) a = b;
}
template <typename T1, typename T2>
inline void print2(T1 a, T2 b) {
  cout << a << " " << b << endl;
}
vector<long long> fac(MAX), finv(MAX), inv(MAX);
int main() {
  long long n, m;
  cin >> n >> m;
  vector<long long> a(n);
  for (long long i = 0; i < (n); i++) cin >> a[i];
  sort((a).rbegin(), (a).rend());
  long long cnt = 0;
  vector<vector<long long> > v(n + 1);
  long long day = 0;
  while (1) {
    bool flag = true;
    for (long long i = 0; i < (m); i++) {
      if (cnt == n) {
        flag = false;
        break;
      }
      v[day].push_back(a[cnt]);
      cnt++;
    }
    if (v[day].empty()) day--;
    if (!flag) break;
    day++;
  }
  vector<long long> sum(m, 0);
  long long ans = 0;
  for (long long i = 0; i < (m); i++) {
    for (long long j = 0; j < (day + 1); j++) {
      if (j == day && v[j].size() < i + 1) break;
      sum[i] += v[j][i];
      ans += v[j][i] * (j + 1);
    }
  }
  day = 0;
  vector<long long> as(n);
  reverse((a).begin(), (a).end());
  for (long long i = 0; i < (n); i++) {
    as[n - 1 - i] = ans;
    ans -= sum[day % m];
    sum[day % m] -= a.back();
    a.pop_back();
    day++;
  }
  for (long long i = 0; i < (n); i++) cout << as[i] << " ";
  cout << endl;
}
