#include <bits/stdc++.h>
using namespace std;
long long int v[(int)(2e6 + 5)], x[(int)(2e6 + 5)], sum;
int main() {
  int n, i, j = 1, a, b, ok = 1, dif, k, s = 1, nr = 0, m, kk;
  cin >> n >> m;
  for (i = 1; i <= n; i++) cin >> v[i];
  sort(v + 1, v + n + 1);
  for (i = 1; i <= n; i++) {
    sum += x[i % m];
    sum += v[i];
    x[i % m] += v[i];
    cout << sum << " ";
  }
  return 0;
}
