#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, m;
  cin >> n >> m;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  long long dp[n], cur = 0;
  for (int i = 0; i < n; i++) {
    cur += a[i];
    dp[i] = cur;
    if (i >= m) {
      dp[i] += dp[i - m];
    }
    cout << dp[i] << " ";
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int T = 1;
  while (T--) {
    solve();
  }
  return 0;
}
