#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 10;
const int MAXM = 1e5 + 10;
const int MAX = 1e9;
const long long INF = 0x3f3f3f3f3f3f3f;
const long long P = 1e9 + 7;
const long long C = 1e5;
int n, m;
long long a[MAXN];
long long sum[MAXN];
long long dp[MAXN];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%I64d", &a[i]);
  }
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n; i++) {
    sum[i] = sum[i - 1] + a[i];
  }
  for (int i = 1; i <= m; i++) {
    dp[i] = sum[i];
  }
  for (int i = m + 1; i <= n; i++) {
    dp[i] = dp[i - m] + sum[i];
  }
  for (int i = 1; i <= n; i++) {
    printf("%I64d ", dp[i]);
  }
  return 0;
}
