-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathC.kt
52 lines (45 loc) · 1.18 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
import java.util.ArrayDeque
fun main() {
val input = System.`in`.bufferedReader()
val output = StringBuilder()
val t = input.readLine()!!.toInt()
repeat(t) {
var (n, k) = input.readLine()!!.split(' ').map { it.toInt() }
val eaten = BooleanArray(n) { false }
var s = input.readLine()!!
var sweet = 0
var ind = ArrayDeque<Int>()
for(i in 0 until n) {
ind.addLast(i + 1)
}
var ok = 0
for(i in s) {
if(i == '1') {
ok++
}
}
if(ok > 0) {
sweet++
ind.removeFirst()
if(s[0] == '1') {
ok--
}
while(ok > 0) {
// println(ind.toString())
var cnt = 0
while(cnt < k - 1) {
ind.addLast(ind.first)
ind.removeFirst()
cnt++
}
if(s[ind.first() - 1] == '1') {
ok--
}
sweet++
ind.removeFirst()
}
}
output.append(("$sweet\n"))
}
print(output)
}