#include <bits/stdc++.h>
using namespace std;
long long a[200005], s[200005], p[200005];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n; i++) s[i] = s[i - 1] + a[i];
  for (int i = 1; i <= n; i++) {
    p[i] = s[i];
    if (i > m) p[i] += p[i - m];
    cout << p[i] << ' ';
  }
}
