#include <bits/stdc++.h>
long int sweet[200000];
long long dp[200000];
using namespace std;
int main() {
  long int n, maxPerDay;
  cin >> n >> maxPerDay;
  for (long int i = 0; i < n; ++i) {
    cin >> sweet[i];
  }
  sort(sweet, sweet + n);
  long long int sum = 0;
  for (int k = 1; k <= n; ++k) {
    sum += sweet[k - 1];
    long long int penalty = dp[k > maxPerDay ? k - maxPerDay : 0] + sum;
    dp[k] = penalty;
    cout << penalty << ' ';
  }
  return 0;
}
