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