#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
int t, n, k;
int a[maxn];
long long sum[maxn], ans[maxn], f[maxn];
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + n + 1);
  sum[1] = a[1];
  for (int i = 2; i <= n; i++) sum[i] = sum[i - 1] + a[i];
  for (int i = 1; i <= k; i++) ans[i] = sum[i];
  for (int i = 1; i <= k; i++) f[i] = sum[i];
  for (int i = k + 1; i <= n; i += k) {
    int l = 1;
    while (l <= k) {
      f[l] += sum[i + l - 1];
      ans[i + l - 1] = f[l];
      l++;
    }
  }
  for (int i = 1; i <= n; i++) printf("%lld ", ans[i]);
  printf("\n");
  return 0;
}
