#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 123;
int n, m;
long long a[N], pref[N], ans[N];
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n; i++) {
    pref[i] = pref[i - 1] + a[i];
  }
  for (int i = 1; i <= n; i++) {
    if (i <= m) {
      ans[i] = pref[i];
    } else
      ans[i] = pref[i] + ans[i - m];
  }
  for (int i = 1; i <= n; i++) {
    cout << ans[i] << ' ';
  }
}
