#include <bits/stdc++.h>
using namespace std;
int n, m;
long long num[200001], sum[200001], ans[200001];
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) cin >> num[i];
  sort(num + 1, num + n + 1);
  for (int i = 1; i <= n; ++i) sum[i] = sum[i - 1] + num[i];
  for (int i = 1; i <= n; ++i) {
    ans[i % m] += sum[i];
    cout << ans[i % m] << ' ';
  }
  return 0;
}
