#include <bits/stdc++.h>
using namespace std;
long long mark[5010];
int main() {
  long long n, m;
  scanf("%lld", &n);
  scanf("%lld", &m);
  long long a[n + 10], d = 0;
  for (long long i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
  }
  vector<long long> v;
  sort(a, a + n);
  long long b[n + 10];
  for (long long i = 0; i < n; i++) {
    if (i < m)
      b[i] = a[i];
    else {
      b[i] = a[i] + b[i - m];
    }
  }
  v.push_back(0);
  for (long long i = 0; i < n; i++) {
    v.push_back(b[i] + v[i]);
  }
  for (long long i = 1; i < v.size(); i++) cout << v[i] << " ";
}
