-
Notifications
You must be signed in to change notification settings - Fork 2
/
13422번 - 도둑.kt
46 lines (37 loc) · 1.08 KB
/
13422번 - 도둑.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
import java.io.BufferedReader
import java.io.InputStreamReader
import java.util.*
fun main() = with(BufferedReader(InputStreamReader(System.`in`))) {
val t = readLine().toInt()
val answer = StringBuilder()
repeat(t) {
val (houseSize, robSize, limit) = readLine().split(" ").map(String::toInt)
val st = StringTokenizer(readLine())
val houses = IntArray(houseSize) { st.nextToken().toInt() }
val count = getCaseCount(houses, robSize, limit)
answer.append(count).appendLine()
}
print(answer)
}
fun getCaseCount(houses: IntArray, robSize: Int, limit: Int): Int {
var start = 0
var end = robSize
var sum = (0 until robSize).sumOf{ i -> houses[i] }
var count = 0
if (robSize == houses.size) {
return if (sum < limit) {
1
}else {
0
}
}
// sum = [start, end) 합
while(start < houses.size) {
if (sum < limit) {
count++
}
sum = sum - houses[start++] + houses[end++]
if (end == houses.size) end = 0
}
return count
}