#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  long long a[200005], s[200005], rez[200005];
  memset(a, 0, n + 5);
  memset(s, 0, n + 5);
  memset(rez, 0, n + 5);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  sort(a, a + n + 1);
  for (int i = 1; i <= n; i++) {
    s[i] = s[i - 1] + a[i];
  }
  for (int i = 1; i <= n; i++) {
    if (i <= m)
      rez[i] = s[i];
    else
      rez[i] = s[i] + rez[i - m];
    cout << rez[i] << " ";
  }
  return 0;
}
