#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e6 + 5;
const int mod = 1e9 + 7;
const int inf = INT_MAX >> 1;
int n, m;
long long int pre[maxn], a[maxn], ans[maxn];
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; ++i) scanf("%lld", &a[i]);
  sort(a + 1, a + 1 + n);
  for (int i = 1; i <= n; i++) {
    pre[i] = pre[i - 1] + a[i];
  }
  int temp = 0;
  temp--;
  temp++;
  for (int i = 1; i <= m; i++) {
    printf("%lld ", pre[i]);
    ans[i] = pre[i];
  }
  for (int i = m + 1; i <= n; i++) {
    ans[i] = pre[i] + ans[i - m];
    printf("%lld ", ans[i]);
  }
  puts("");
}
