#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  vector<long long> mass(n);
  for (int i = 0; i < n; i++) {
    cin >> mass[i];
  }
  sort(mass.begin(), mass.end());
  vector<long long> ans(n);
  vector<long long> addition(m, 0);
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    sum += mass[i] + addition[i % m];
    addition[i % m] += mass[i];
    cout << sum << ' ';
  }
  cout << endl;
  return 0;
}
