#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
long long arr[maxn], prefix[maxn], sum[maxn];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) cin >> arr[i];
  sort(arr + 1, arr + n + 1);
  for (int i = 1; i <= n; ++i) prefix[i] = prefix[i - 1] + arr[i];
  long long cur = 0;
  for (int i = 1; i <= n; ++i) {
    sum[i % m] += arr[i];
    cur += sum[i % m];
    cout << cur << ' ';
  }
  cout << '\n';
  return 0;
}
