#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int n, m;
  cin >> n >> m;
  vector<long long> A(n);
  for (long long &x : A) cin >> x;
  sort(A.begin(), A.end());
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    if (i >= m) A[i] += A[i - m];
    ans += A[i];
    cout << ans << " ";
  }
  cout << "\n";
  return 0;
}
