#include <bits/stdc++.h>
using namespace std;
long long arr[200005];
long long pref[200005];
long long n, m;
int main() {
  cin >> n >> m;
  for (int x = 1; x <= n; x++) {
    cin >> arr[x];
  }
  sort(arr + 1, arr + n + 1);
  long long seb = 0;
  for (int x = 1; x <= n; x++) {
    long long cur = seb + pref[x % m] + arr[x];
    pref[x % m] += arr[x];
    seb = cur;
    printf("%lld ", cur);
  }
}
