#include <bits/stdc++.h>
using namespace std;
long long n, m;
vector<long long> v;
vector<long long> v2;
long long x;
long long res[2000200];
long long d[2000200];
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> x;
    v.push_back(x);
  }
  sort(v.begin(), v.end());
  d[0] = v[0];
  for (int i = 1; i < n; i++) {
    d[i] = d[i - 1] + v[i];
  }
  res[0] = v[0];
  for (int i = 1; i < m; i++) {
    res[i] = d[i];
  }
  for (int i = m; i < n; i++) {
    res[i] = res[i - m] + d[i];
  }
  for (int i = 0; i < n; i++) {
    cout << res[i] << " ";
  }
}
