#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k, i;
  cin >> n >> k;
  long long a[n], sum, sum1 = 0;
  vector<long long> v;
  for (i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  for (i = 0; i < n; i++) {
    sum1 += a[i];
    if (i > k - 1)
      sum = sum1 + v[i - k];
    else
      sum = sum1;
    v.push_back(sum);
  }
  for (i = 0; i < v.size(); i++) cout << v[i] << " ";
  return 0;
}
