#include <bits/stdc++.h>
using namespace std;
int power(int a, int b, int m, int ans = 1) {
  for (; b; b >>= 1, a = 1LL * a * a % m)
    if (b & 1) ans = 1LL * ans * a % m;
  return ans;
}
const int NN = 200011;
int a[NN];
long long dp[NN];
long long sum[NN];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  sort(a + 1, a + n + 1);
  long long now = 0;
  long long s = 0;
  for (int i = 1; i <= n; i++) {
    sum[i] = sum[i - 1] + a[i];
    dp[i] = sum[i];
    if (i >= m) dp[i] += dp[i - m];
    printf("%I64d ", dp[i]);
  }
  return 0;
}
