#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 100;
int m, n;
long long sweets[MAXN];
vector<long long> sol;
long long weightedSum;
long long sums[MAXN];
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> sweets[i];
  }
  sort(sweets, sweets + n);
  for (int i = 0; i < n;) {
    for (int j = 0; j < m && i + j < n; j++) {
      sums[j] += sweets[i + j];
      weightedSum += sums[j];
      sol.push_back(weightedSum);
    }
    i += m;
  }
  for (int i = 0; i < sol.size(); i++) {
    cout << sol[i] << " ";
  }
  cout << endl;
  return 0;
}
