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