#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  long long int a[n + 1], b[n + 1];
  a[0] = 0;
  b[0] = 0;
  for (int i = 1; i <= n; i++) cin >> a[i], b[i] = a[i];
  sort(a, a + n + 1);
  for (int i = 2; i <= n; i++) a[i] += a[i - 1];
  for (int i = 1; i <= n; i++) {
    if (i - m > 0)
      b[i] = a[i] + b[i - m];
    else
      b[i] = a[i];
    cout << b[i] << " ";
  }
}
