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