#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
int read() {
  int x = 0, flag = 1;
  char c = getchar();
  while ((c > '9' || c < '0') && c != '-') c = getchar();
  if (c == '-') flag = 0, c = getchar();
  while (c <= '9' && c >= '0') {
    x = (x << 3) + (x << 1) + c - '0';
    c = getchar();
  }
  return flag ? x : -x;
}
const int maxn = 2e5 + 5;
long long f[maxn], s[maxn];
int main() {
  int n = read(), m = read();
  for (int i = (1); i <= (int)(n); i++) s[i] = read();
  sort(s + 1, s + n + 1);
  for (int i = (1); i <= (int)(n); i++) s[i] += s[i - 1];
  for (int i = (1); i <= (int)(m); i++) f[i] = s[i];
  for (int i = (1); i <= (int)(m); i++)
    for (int j = i + m; j <= n; j += m) f[j] = f[j - m] + s[j];
  for (int i = (1); i <= (int)(n); i++) printf("%lld ", f[i]);
  return 0;
}
