#include <bits/stdc++.h>
using namespace std;
long long int arr[200010], arr2[200010], ans[200010];
int n, m;
void input() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
}
void logic() {
  sort(arr, arr + n);
  arr2[0] = arr[0];
  for (int i = 1; i < n; i++) {
    arr2[i] = arr2[i - 1] + arr[i];
  }
  for (int i = 0; i < m; i++) {
    ans[i] = arr2[i];
  }
  for (int i = m; i < n; i++) {
    ans[i] += arr2[i] + ans[i - m];
  }
}
void output() {
  for (int i = 0; i < n; i++) {
    cout << ans[i] << " ";
  }
  cout << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(NULL);
  input();
  logic();
  output();
  return 0;
}
