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