#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, m;
  cin >> n >> m;
  vector<long long> sweetness;
  for (long long i = 0; i < n; i++) {
    long long ele;
    cin >> ele;
    sweetness.push_back(ele);
  }
  vector<long long> modular = vector<long long>(m, 0);
  sort(sweetness.begin(), sweetness.end());
  long long cur = 0;
  for (long long i = 0; i < n; i++) {
    cur += sweetness[i];
    cur += modular[i % m];
    cout << cur << " ";
    modular[i % m] += sweetness[i];
  }
}
