#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, i, j, x, m;
  cin >> n >> m;
  long long a[n];
  for (i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  long long ans = 0, cur;
  x = cur = 0;
  map<long long, long long> mp;
  for (i = 0; i < n; i++) {
    mp[i] = a[i];
    mp[i] += mp[i - m];
  }
  for (i = n - 1; i >= 0; i--) {
    if (x == 0) cur++;
    ans += a[i] * cur;
    x = (x + 1) % m;
  }
  vector<long long> v;
  for (i = n - 1; i >= 0; i--) {
    v.push_back(ans);
    ans -= mp[i];
  }
  for (i = n - 1; i >= 0; i--) cout << v[i] << " ";
}
