#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 20;
long long n, m, a[maxn], dp[maxn];
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  dp[0] = a[0];
  for (int i = m; i < n; i++) a[i] += a[i - m];
  for (int i = 1; i < n; i++) dp[i] = dp[i - 1] + a[i];
  for (int i = 0; i < n; i++) cout << dp[i] << " ";
  return 0;
}
