#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
const int inf = 1e9 + 10;
long long a[N], ps[N], ans[N];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + 1 + n);
  ps[0] = 0;
  for (int i = 1; i <= n; i++) ps[i] = ps[i - 1] + a[i];
  for (int i = 1; i <= n; i++) {
    if (i <= m)
      ans[i] = ps[i];
    else
      ans[i] = ans[i - m] + ps[i];
  }
  for (int i = 1; i <= n; i++) cout << ans[i] << ' ';
  return 0;
}
