```go
package main
import (
"bufio"
"container/heap"
"fmt"
"os"
)
type Item struct {
c int64
i int
}
type MaxHeap []Item
func (h MaxHeap) Len() int { return len(h) }
func (h MaxHeap) Less(i, j int) bool { return h[i].c > h[j].c || (h[i].c == h[j].c && h[i].i < h[j].i) }
func (h MaxHeap) Swap(i, j int) { h[i], h[j] = h[j], h[i] }
func (h *MaxHeap) Push(x interface{}) { *h = append(*h, x.(Item)) }
func (h *MaxHeap) Pop() interface{} {
old := *h
n := len(old)
x := old[n-1]
*h = old[:n-1]
return x
}
var rdr = bufio.NewReaderSize(os.Stdin, 1<<20)
func nextInt() int {
sign := 1
v := 0
c, _ := rdr.ReadByte()
for (c < '0' || c > '9') && c != '-' {
c, _ = rdr.ReadByte()
}
if c == '-' {
sign = -1
c, _ = rdr.ReadByte()
}
for c >= '0' && c <= '9' {
v = v*10 + int(c-'0')
c, _ = rdr.ReadByte()
}
return sign * v
}
func main() {
out := bufio.NewWriterSize(os.Stdout, 1<<20)
defer out.Flush()
n := nextInt()
k := nextInt()
c := make([]int64, n+1)
for i := 1; i <= n; i++ {
c[i] = int64(nextInt())
}
t := make([]int, n+1)
h := &MaxHeap{}
heap.Init(h)
p := 1
var total int64
for time := k + 1; time <= k+n; time++ {
for p <= n && p <= time {
heap.Push(h, Item{c: c[p], i: p})
p++
}
it := heap.Pop(h).(Item)
t[it.i] = time
total += int64(time-it.i) * it.c
}
fmt.Fprintln(out, total)
for i := 1; i <= n; i++ {
if i > 1 {
out.WriteByte(' ')
}
fmt.Fprint(out, t[i])
}
out.WriteByte('\n')
}
```