#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t = 1;
  while (t--) {
    int n, m;
    cin >> n >> m;
    int ar[n + 1];
    for (int i = 1; i <= n; i++) cin >> ar[i];
    sort(ar + 1, ar + n + 1);
    unsigned long long b[m + 1];
    for (int i = 0; i <= m; i++) b[i] = 0;
    unsigned long long s = 0;
    for (int i = 1; i <= n; i++) {
      b[(i - 1) % m + 1] += ar[i];
      s += b[(i - 1) % m + 1];
      cout << s << " ";
    }
  }
  return 0;
}
