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