#include <bits/stdc++.h>
using namespace std ;
#define ll long long
#define pb push_back
#define all(x) x.begin(), x.end()
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define per(i,b,a) for(int i = b; i >= a; i--)
#define lower lower_bound
#define upper upper_bound
#define sz(x) (int)x.size()
const int N = 1e6 + 1 ;
ll t[2][N] ;
int n , k , a[N] ;
void upd(int id , int x , int p){
while(id <= n){
t[p][id] += x ;
id += (id & (-id)) ;
}
}
ll get(int id , int p){
ll sum = 0 ;
while(id > 0) sum += t[p][id] , id -= (id & (-id)) ;
return sum ;
}
void solve(){
cin >> n >> k ;
int mn , mx ;
mn = INT_MAX ;
mx = INT_MIN ;
set<int> kf ;
rep(i , 1 , n){
cin >> a[i] ;
kf.insert(a[i]) ;
// kf.insert(a[i] - 1) ;
mn = min(mn , a[i]) ;
mx = max(mx , a[i]) ;
if(k == 1) cout << 0 << ' ';
}
map<int,int> compress ;
int cnt = 0 ;
for(auto x : kf) compress[x] = ++cnt ;
if(k == 1) return ;
int l , r ;
multiset<int> x , y ;
l = 1 , r = 0 ;
ll ans = 0 ;
while(l <= n - k + 1){
while(r <= n && sz(x) + sz(y) < k){
r++ ;
int cnt = k / 2 ;
if(sz(x) < cnt){
x.insert(a[r]);
upd(compress[a[r]] , a[r] , 0) ;
}else{
if(a[r] <= *(--x.end())){
x.insert(a[r]) ;
upd(compress[a[r]] , a[r] , 0) ;
auto it = x.end() ; it-- ;
upd(compress[*it] , *it , 1) ;
y.insert(*it) ;
upd(compress[*it] , -*it , 0) ;
x.erase(it) ;
}else{
upd(compress[a[r]] , a[r] , 1) ;
y.insert(a[r]) ;
}
}
}
ll mid ;
if(k & 1){
mid = *y.begin() ;
}else{
mid = *(--x.end()) ;
}
ll L , R ;
ll del1 , del2 ;
if(k & 1){
L = mid * sz(x) + mid ;
del1 = get(compress[mid] , 0) + mid ;
R = mid * sz(y) ;
del2 = get(compress[mx] , 1) - get(compress[mid] - 1 , 1) ;
}else{
L = mid * sz(x) ;
del1 = get(compress[mid] , 0) ;
R = mid * sz(y) + mid ;
del2 = get(compress[mx] , 1) - get(compress[mid] - 1 , 1) + mid ;
}
ans = 0 ;
// cout << del1 << ' ' << del2 << " " << ' ' << L << ' ' << R << " " ;
ans += (L - del1) ;
ans += (del2 - R) ;
cout << ans << " " ;
if(x.find(a[l]) != x.end()){
x.erase(x.find(a[l])) ;
upd(compress[a[l]] , -a[l] , 0) ;
if(sz(y)) x.insert(*(y.begin())) , upd(compress[*y.begin()] , *y.begin() , 0) , upd(compress[*y.begin()] , -*y.begin() , 1) , y.erase(y.begin()) ;
}else{
y.erase(y.find(a[l])) ;
upd(compress[a[l]] , -a[l] , 1) ;
}
l++ ;
}
}
int main(){
#ifdef Wizzard
freopen(".in" , "r" , stdin) ;
#endif
ios::sync_with_stdio(false) ;
cin.tie(0) ;
int t = 1 ;
// cin >> t ;
rep(i , 1 , t){
solve() ;
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQgOwogCiNkZWZpbmUgbGwgbG9uZyBsb25nCiNkZWZpbmUgcGIgcHVzaF9iYWNrCiNkZWZpbmUgYWxsKHgpIHguYmVnaW4oKSwgeC5lbmQoKQojZGVmaW5lIHJlcChpLGEsYikgZm9yKGludCBpID0gYTsgaSA8PSBiOyBpKyspCiNkZWZpbmUgcGVyKGksYixhKSBmb3IoaW50IGkgPSBiOyBpID49IGE7IGktLSkKI2RlZmluZSBsb3dlciBsb3dlcl9ib3VuZAojZGVmaW5lIHVwcGVyIHVwcGVyX2JvdW5kCiNkZWZpbmUgc3ooeCkgKGludCl4LnNpemUoKQogCmNvbnN0IGludCBOID0gMWU2ICsgMSA7CiAKbGwgdFsyXVtOXSA7CmludCBuICwgayAsIGFbTl0gOwogCnZvaWQgdXBkKGludCBpZCAsIGludCB4ICwgaW50IHApewoJd2hpbGUoaWQgPD0gbil7CgkJdFtwXVtpZF0gKz0geCA7CgkJaWQgKz0gKGlkICYgKC1pZCkpID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