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