#include <bits/stdc++.h>
using namespace std;
vector<bool> is_prime(1e6, true);
int main() {
  long long n, m;
  cin >> n >> m;
  long long a[n];
  for (long long i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  long long pre_sum[n];
  pre_sum[0] = a[0];
  for (long long i = 1; i < n; i++) pre_sum[i] = a[i] + pre_sum[i - 1];
  long long b[n];
  for (long long i = 0; i < n; i++) {
    if (i + 1 <= m) {
      b[i] = pre_sum[i];
    } else {
      b[i] = pre_sum[i] + b[i - m];
    }
  }
  for (long long i = 0; i < n; i++) cout << b[i] << " ";
}
