#include <bits/stdc++.h>
#pragma comment(linker, "/stack:640000000")
using namespace std;
const double EPS = 1e-9;
const int INF = 0x7f7f7f7f;
const double PI = acos(-1.0);
template <class T>
inline T gcd(T a, T b) {
  return (b) == 0 ? (a) : gcd((b), ((a) % (b)));
}
template <class T>
inline T lcm(T a, T b) {
  return ((a) / gcd((a), (b)) * (b));
}
template <typename T>
string NumberToString(T Number) {
  ostringstream second;
  second << Number;
  return second.str();
}
struct debugger {
  template <typename T>
  debugger& operator,(const T& v) {
    cerr << v << " ";
    return *this;
  }
} dbg;
int t, n, m;
string s;
int arr[200005];
long long cum[200005];
vector<long long> ans;
int main() {
  while (~scanf("%d%d", &n, &m)) {
    for (int i = 1; i <= (n); i++) scanf("%d", &arr[i]);
    sort(arr + 1, arr + 1 + n);
    ans.clear();
    memset(cum, 0, sizeof(cum));
    deque<int> dq;
    for (int i = 1; i <= (n); i++) cum[i] += cum[i - 1] + arr[i];
    for (int i = 1; i <= (m); i++) dq.push_back(arr[i]);
    long long sum = 0;
    for (int i = 1; i <= (m); i++) {
      sum += arr[i];
      ans.push_back(sum);
    }
    sum = 0;
    for (int i = 0; i < (m); i++) sum += dq[i];
    int rght = m + 1;
    while (rght <= n) {
      sum -= dq.front();
      dq.pop_front();
      dq.push_back(arr[rght]);
      sum += dq.back();
      int indx = rght - m - 1;
      long long tmp = ans[indx] + cum[indx + 1];
      ans.push_back(tmp + sum);
      rght++;
    }
    for (int i = 0; i < (n); i++) printf("%lld ", ans[i]);
    puts("");
  }
  return 0;
}
