#include <bits/stdc++.h>
using namespace std;
int n, m, x;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  vector<long long> v(n + 1, 0);
  vector<long long> ans(n + 1, 0);
  vector<long long> sub[m + 1];
  for (int i = 1; i <= n; i++) {
    cin >> v[i];
  }
  sort(v.begin(), v.end());
  long long day = 1LL;
  for (int i = 1; i <= n; i++) {
    if (day > m) day = 1;
    if (i <= m)
      sub[day].push_back(v[i]);
    else
      sub[day].push_back(sub[day][sub[day].size() - 1] + v[i]);
    ans[i] = ans[i - 1] + sub[day][sub[day].size() - 1];
    cout << ans[i] << " ";
    day++;
  }
  cout << "\n";
  return 0;
}
