https://www.acmicpc.net/problem/2143
import sys
from bisect import bisect_left, bisect_right
def generate(arr, n):
ret = []
for i in range(n):
ret.append(arr[i])
tmp = arr[i]
for j in range(i + 1, n):
tmp += arr[j]
ret.append(tmp)
return sorted(ret)
t = int(sys.stdin.readline())
a, arrA = int(sys.stdin.readline()), list(map(int, sys.stdin.readline().split()))
b, arrB = int(sys.stdin.readline()), list(map(int, sys.stdin.readline().split()))
sumA, sumB = generate(arrA, a), generate(arrB, b)
ans = 0
for numA in sumA:
right = bisect_right(sumB, t - numA)
left = bisect_left(sumB, t - numA)
ans += right - left
print(ans)
우와 정말 깔끔하게 잘 푸셨네요~! ^^ㅎㅎ