#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const int N = 7e3 + 3;
const int oo = 1e8;
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
int n;
int m;
vector<long long> v, sum;
int vis[1000009];
int main() {
  ios::sync_with_stdio(0);
  cin >> n;
  v.resize(n);
  cin >> m;
  sum.resize(n, 0);
  for (int c = 0; c < n; c++) {
    cin >> v[c];
  }
  long long s = 0;
  sort(v.begin(), v.end());
  for (int c = 0; c < n; c++) {
    s += v[c];
    sum[c] = s;
    if (c >= m) {
      sum[c] += sum[c - m];
    }
    cout << sum[c] << " ";
  }
  return 0;
}
