#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<long long> V(n), dp(n, 0);
  for (int i = 0; i < n; i++) {
    cin >> V[i];
  }
  sort(V.begin(), V.end());
  dp[0] = V[0];
  for (int i = 1; i < n; i++) {
    dp[i] = dp[i - 1] + V[i];
  }
  vector<long long> ans(n, 0);
  for (int i = 0; i < m; i++) {
    ans[i] = dp[i];
    cout << ans[i] << ' ';
  }
  for (int i = m; i < n; i++) {
    ans[i] = ans[i - m] + dp[i];
    cout << ans[i] << ' ';
  }
  return 0;
}
