-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathC.kt
62 lines (49 loc) · 1.41 KB
/
C.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import java.lang.AssertionError
private val input = System.`in`.bufferedReader()
private val output = StringBuilder()
private fun readLn() = input.readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readLong() = readLn().toLong() // single long
private fun readDouble() = readLn().toDouble() // single double
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints
private fun readLongs() = readStrings().map { it.toLong() } // list of longs
private fun readDoubles() = readStrings().map { it.toDouble() } // list of doubles
private fun myAssert(x: Boolean) {
if (!x) {
throw AssertionError()
}
}
private fun runCase() {
var(n, k) = readInts()
var a = readInts()
var prefixSums = IntArray(n)
prefixSums[0] = a[0]
for (i in 1 until n) {
prefixSums[i] = prefixSums[i-1] + a[i]
}
if(n == 1) {
output.append("${a[0]}\n")
return
}
var ans = 0
var cnt = 1
for (i in n-2 downTo 0) {
cnt++
var sum = 0
if(i - 1 >= 0) {
sum -= prefixSums[i-1]
}
sum += prefixSums[i + (cnt / k) - 1]
ans = maxOf(ans, sum)
}
output.append("$ans\n")
}
fun main(args: Array<String>) {
var t: Int = 1
t = readInt()
repeat(t) {
runCase()
}
print(output)
}