#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long n, m;
  cin >> n >> m;
  long long a[n];
  vector<long long> b[m];
  for (long long i = 0; i < n; ++i) cin >> a[i];
  sort(a, a + n);
  for (long long i = 0; i < n; ++i) b[i % m].emplace_back(a[i]);
  for (long long i = 0; i < m; ++i) {
    for (long long j = 1; j < (long long)(b[i].size()); ++j) {
      b[i][j] += b[i][j - 1];
    }
  }
  long long ans = 0;
  for (long long i = 0; i < n; ++i) {
    long long k = i / m;
    ans += b[i % m][k];
    cout << ans << ' ';
  }
  return 0;
}
