#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int a[maxn + 5];
long long sum[maxn + 5];
long long ans[maxn + 5];
bool cmp(int a, int b) { return a > b; }
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  sort(a + 1, a + 1 + n, cmp);
  ans[n + 1] = 0;
  if (n == 1)
    printf("%d\n", a[1]);
  else {
    for (int i = n; i >= 1; i--) {
      int k = n - i + 1;
      if (k > m)
        sum[k] = sum[k - m] + a[i];
      else
        sum[k] = a[i];
      ans[i] = ans[i + 1] + sum[k];
    }
    for (int i = n; i >= 1; i--) {
      printf("%lld", ans[i]);
      if (i != 1) printf(" ");
    }
    printf("\n");
  }
  return 0;
}
