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