#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 100;
long long a[maxn], b[maxn];
void solve() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) scanf("%lld", &a[i]);
  sort(a, a + n);
  long long sum(0), cnt(0);
  for (int i = 0; i < n; ++i) {
    if (i) cout << " ";
    b[i % m] += a[i];
    sum += b[i % m];
    cout << sum;
  }
}
int main() {
  int t;
  solve();
}
