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