https://codeforces.com/problemset/problem/1253/C
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn=2e5+5;
ll a[maxn],sum[maxn];
ll ans[maxn];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int n,m;
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++){
sum[i]=sum[i-1]+a[i];
}
for(int i=1;i<=n;i++){
if(i-m>=0)ans[i]=ans[i-m]+sum[i];
else ans[i]=sum[i];//如果i小于m直接加上前缀和即可
}
for(int i=1;i<=n;i++){
cout<<ans[i]<<" ";
}
cout<<endl;
return 0;
}