#include <bits/stdc++.h>
using namespace std;
long long mod(long long x) {
  return ((x % 1000000007 + 1000000007) % 1000000007);
}
long long add(long long a, long long b) { return mod(mod(a) + mod(b)); }
long long mul(long long a, long long b) { return mod(mod(a) * mod(b)); }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  t = 1;
  while (t--) {
    int n, m;
    cin >> n >> m;
    vector<long long> v(n + 1), pref(n + 1), res(n + 1);
    pref[0] = 0;
    for (int i = 1; i < n + 1; i++) cin >> v[i];
    sort(v.begin(), v.end());
    for (int i = 1; i < n + 1; i++) pref[i] = v[i] + pref[i - 1];
    for (int i = 1; i < n + 1; i++) {
      if (i <= m)
        res[i] = pref[i];
      else
        res[i] = pref[i] + res[i - m];
    }
    for (int i = 1; i < n + 1; i++) cout << res[i] << " ";
  }
}
