#include <bits/stdc++.h>
using namespace std;
long long t, n, m, a[200010], s[200010];
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (long long i = (1), i__end = (n + 1); i < i__end; i++) cin >> a[i];
  sort(a + 1, a + n + 1);
  long long sum = 0;
  for (long long k = (1), k__end = (n + 1); k < k__end; k++) {
    s[k % m] += a[k];
    sum += s[k % m];
    cout << sum << ' ';
  }
  cout << endl;
  return 0;
}
