def find_min_cost(N, K, prices):
fish = [0] * N
totalPrice = 0
for day in range(1, N + 1):
myFish = sum(fish) - day + 1
todayFish = 0
if myFish == 0:
totalPrice += prices[day - 1]
todayFish += 1
myFish += 1
cheapestPrice = prices[day - 1]
cheapestDay = day
for futureDay in range(day + 1, min(day + K, N + 1)):
if prices[futureDay - 1] < cheapestPrice:
cheapestPrice = prices[futureDay - 1]
cheapestDay = futureDay
if cheapestDay == day and myFish < N - day + 1:
totalPrice += cheapestPrice * (K - myFish)
todayFish += K - myFish
fish[day - 1] = todayFish
return totalPrice, fish
N, K = map(int, input().split())
prices = list(map(int, input().split()))
min_cost, fish_per_day = find_min_cost(N, K, prices)
print(min_cost)
print(*fish_per_day)