← Home
```go
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

func main() {
	// Set up fast I/O
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var n, k int
	// Reading input n and k
	fmt.Fscan(reader, &n, &k)

	c := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &c[i])
	}

	// Sort c in descending order to maximize score
	sort.Slice(c, func(i, j int) bool {
		return c[i] > c[j]
	})

	// q[i] stores the prefix sum of the first i elements of sorted c
	// q[i] corresponds to the score obtained by defeating the i-th boss in the sequence 
	// (where the sequence is formed by optimal ordering 1..n) relative to a base.
	// Actually, Q values represent the "height" of the score function derivative.
	q := make([]int64, n+1)
	var currentQ int64
	for i := 0; i < n; i++ {
		currentQ += int64(c[i])
		q[i+1] = currentQ
	}

	// ssQ[i] stores the prefix sum of the q array
	// ssQ[i] = sum(q[1]...q[i])
	ssQ := make([]int64, n+1)
	for i := 1; i <= n; i++ {
		ssQ[i] = ssQ[i-1] + q[i]
	}

	// Initialize answer with a very small number
	ans := int64(-4e18)
	currentS := int64(0)
	pos := n
	rVal := k + 1

	// Iterate backwards from n to 0 using steps of size at most rVal
	for pos > 0 {
		// We want to make a jump of size j (1 <= j <= rVal) to reach 'next_pos'
		// and then switch to steps of size 1 for the remainder of the path to 0.
		// Switching to steps of size 1 at 'next_pos' gives a remaining score of ssQ[next_pos].
		// We want to maximize ssQ[next_pos] in the reachable range.
		
		low := pos - rVal
		if low < 0 {
			low = 0
		}
		high := pos - 1

		// Find max ssQ in range [low, high]
		maxSS := int64(-4e18)
		for i := low; i <= high; i++ {
			if ssQ[i] > maxSS {
				maxSS = ssQ[i]
			}
		}

		// Update global maximum score
		if currentS+maxSS > ans {
			ans = currentS + maxSS
		}

		// If we cannot make a full step of size rVal, we must stop (transition handled above)
		if pos < rVal {
			break
		}

		// Take the greedy step of size rVal
		pos -= rVal
		
		// If we landed on a valid non-zero index, add its Q value
		if pos > 0 {
			currentS += q[pos]
		}
	}

	fmt.Fprintln(writer, ans)
}
```