#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 2e5 + 5;
int n, m;
ll a[N], b[N], res;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  sort(a + 1, a + 1 + n);
  for (int i = 1; i <= n; ++i) {
    b[i % m] += a[i];
    res += b[i % m];
    cout << res << " ";
  }
  return 0;
}
