#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
long long a[N], dp[N];
int main() {
  int n;
  long long m;
  scanf("%d%lld", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
  sort(a + 1, a + 1 + n);
  long long sum = 0;
  for (int i = 1; i <= n; i++) {
    sum += a[i];
    if (i > m) {
      dp[i] = sum + dp[i - m];
    } else {
      dp[i] = sum;
    }
    cout << dp[i] << " ";
  }
}
