Skip to content

Instantly share code, notes, and snippets.

@maehrm
Last active February 15, 2026 01:25
Show Gist options
  • Select an option

  • Save maehrm/5372890a0e0e8ccbebb498da43690719 to your computer and use it in GitHub Desktop.

Select an option

Save maehrm/5372890a0e0e8ccbebb498da43690719 to your computer and use it in GitHub Desktop.
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
sumA = [0]
for i in range(N):
sumA.append(sumA[-1] + A[i])
sumB = [0]
for i in range(M):
sumB.append(sumB[-1] + B[i])
ans = 0
for i in range(len(sumA)):
# Aをi冊選んだとき、Bが何冊読めるか?
rest = K - sumA[i]
if rest < 0:
continue
ok, ng = 0, len(sumB)
while ng - ok > 1:
mid = (ok + ng) // 2
if sumB[mid] <= rest:
ok = mid
else:
ng = mid
ans = max(i + ok, ans)
print(ans)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment