#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long int lcm(long long int a, long long int b) {
  return (a * b) / gcd(a, b);
}
long long int fib(long long int n) {
  if (n == 0 || n == 1) {
    return 1;
  } else {
    long long int arr[n + 1];
    arr[0] = 0;
    arr[1] = 1;
    for (long long int i = 2; i <= n; i++) {
      arr[i] = arr[i - 1] + arr[i - 2];
    }
    return arr[n];
  }
}
long long int mpow(long long int base, long long int exp) {
  base %= 1000000007;
  long long int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((long long int)result * base) % 1000000007;
    base = ((long long int)base * base) % 1000000007;
    exp >>= 1;
  }
  return result;
}
long long int is_prime(long long int a) {
  long long int i;
  if (a == 2 || a == 3)
    return 1;
  else
    for (i = 2; i * i <= a; i++) {
      if (a % i == 0) return 0;
    }
  return 1;
}
long long int countSetBits(long long int n) {
  if (n == 0)
    return 0;
  else
    return (n & 1) + countSetBits(n >> 1);
}
long long int XOR(long long int n) {
  switch (n & 3) {
    case 0:
      return n;
    case 1:
      return 1;
    case 2:
      return n + 1;
    case 3:
      return 0;
  }
}
long long int arsum(long long int arr[], int k) {
  long long int i = 0;
  long long int sum = 0;
  for (long long int i = 0; i <= k; i++) {
    sum += arr[i];
  }
  return sum;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int i = 0, j = 0;
  long long int n, m;
  cin >> n >> m;
  long long int arr[n];
  long long int sum = 0, s[n];
  for (long long int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  sort(arr, arr + n);
  for (long long int i = 0; i < n; i++) {
    s[i] = sum + arr[i];
    sum += arr[i];
  }
  long long int dp[n];
  dp[0] = arr[0];
  for (long long int i = 1; i < m; i++) {
    dp[i] = dp[i - 1] + arr[i];
  }
  for (long long int i = m; i < n; i++) {
    dp[i] = dp[i - m] + s[i];
  }
  for (long long int i = 0; i < n; i++) {
    cout << dp[i] << " ";
  }
}
