#include <bits/stdc++.h>
using namespace std;
int n, m;
int A[200005];
vector<int> B[200005], id;
long long row[200005];
int cnt = 0;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d", &A[i]);
  }
  sort(A, A + n);
  cnt = 0;
  for (int i = 0; i < n; i++) {
    if (B[cnt].size() == m) cnt++;
    B[cnt].push_back(A[i]);
  }
  cnt = 0;
  int pos = 0;
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    row[pos] += B[cnt][pos];
    ans += row[pos];
    pos++;
    if (pos == m) {
      cnt++;
      pos = 0;
    }
    printf("%lld", ans);
    if (i < n)
      printf(" ");
    else
      printf("\n");
  }
  return 0;
}
