#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, m, x, a[200055] = {0}, s = 0;
  cin >> n >> m;
  vector<long long int> v;
  for (long long int i = 0; i < n; i++) {
    cin >> x;
    v.push_back(x);
  }
  sort(v.begin(), v.end());
  for (long long int i = 0; i < n; i++) {
    a[i % m] += v[i];
    s += a[i % m];
    cout << s << ' ';
  }
}
