#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m;
  cin >> n >> m;
  vector<long long> v(n), a(n);
  for (auto &x : v) cin >> x;
  sort(v.begin(), v.end());
  long long s = 0;
  for (long long i = 0; i < n; i++) {
    s += v[i];
    a[i] = s;
    if (i >= m) a[i] += a[i - m];
  }
  for (long long i = 0; i < n; i++) cout << a[i] << " ";
  return 0;
}
