#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long i, j, k, n, m;
  cin >> n >> m;
  vector<long long> arr(n);
  for (i = 0; i < n; ++i) cin >> arr[i];
  sort(arr.begin(), arr.end());
  vector<long long> pre_sum(n, 0), dp(n, 0);
  pre_sum[0] = dp[0] = arr[0];
  for (i = 1; i < n; ++i) {
    if (i < m) {
      pre_sum[i] += pre_sum[i - 1] + arr[i];
      dp[i] = pre_sum[i];
    } else {
      pre_sum[i] += pre_sum[i - 1] + arr[i];
      dp[i] = dp[i - m] + pre_sum[i];
    }
  }
  for (i = 0; i < n; ++i) {
    cout << dp[i] << " ";
  }
  cout << "\n";
  return 0;
}
