34 lines
765 B
Swift
34 lines
765 B
Swift
func solve() {
|
|
guard let input1 = readLine(),
|
|
let NS = input1.split(separator: " ").compactMap({Int($0)}) as? [Int],
|
|
let N = NS.first, let S = NS.last
|
|
else { return }
|
|
|
|
guard let input2 = readLine(),
|
|
let seq = input2.split(separator: " ").compactMap({Int($0)}) as? [Int]
|
|
else { return }
|
|
|
|
var minLength = Int.max
|
|
var L = 0, R = 0
|
|
var acc = 0
|
|
|
|
while true {
|
|
if acc >= S {
|
|
minLength = min(minLength, R-L)
|
|
acc -= seq[L]
|
|
L += 1
|
|
}
|
|
else if R == N {
|
|
break
|
|
}
|
|
else {
|
|
acc += seq[R]
|
|
R += 1
|
|
}
|
|
}
|
|
|
|
let result = minLength == Int.max ? 0 : minLength
|
|
print(result)
|
|
}
|
|
|
|
solve() |