#include <bits/stdc++.h>
using namespace std;
long long dp[200000 + 1];
int main() {
  int n, m;
  cin >> n >> m;
  int sweet[200000];
  for (int i = 0; i < n; i++) {
    cin >> sweet[i];
  }
  sort(sweet, sweet + n);
  long long int sweetSum = 0;
  for (int k = 1; k <= n; k++) {
    sweetSum += sweet[k - 1];
    dp[k] = (k <= m ? 0 : dp[k - m]) + sweetSum;
    cout << dp[k] << " ";
  }
  cout << endl;
  return 0;
}
