#include <bits/stdc++.h>
using namespace std;
long long sum[200005];
int main() {
  long long n, m;
  cin >> n >> m;
  long long a[n];
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
  }
  sort(a + 1, a + n + 1);
  long long s = 0;
  for (long long i = 1; i <= m; i++) {
    s += a[i];
    sum[i % m] += s;
    cout << sum[i % m] << ' ';
  }
  for (long long i = m + 1; i <= n; i++) {
    s += a[i];
    sum[i % m] += s;
    cout << sum[i % m] << ' ';
  }
  cout << endl;
  return 0;
}
