2025-11-21 21:41:44 +09:00

33 lines
848 B
Swift

if let T = Int(readLine() ?? ""),
let n = Int(readLine() ?? ""),
let inputA = readLine(),
let A = inputA.split(separator: " ").compactMap({Int($0)}) as? [Int],
let m = Int(readLine() ?? ""),
let inputB = readLine(),
let B = inputB.split(separator: " ").compactMap({Int($0)}) as? [Int],
A.count == n , B.count == m
{
var countSumB = [Int: Int]()
for i in 0..<m {
var currentSumB = 0
for j in i..<m {
currentSumB += B[j]
countSumB[currentSumB, default: 0] += 1
}
}
var ans = 0
for i in 0..<n {
var currentSumA = 0
for j in i..<n {
currentSumA += A[j]
let target = T - currentSumA
if let cnt = countSumB[target] {
ans += cnt
}
}
}
print(ans)
}