Buggy python submission (verdict: Time Limit Exceeded):
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
a.insert(0,0)
b.insert(0,0)

sum_a = [0]
for i in range(1,len(a)):
    sum_a.append(sum_a[i-1] + a[i])
    if sum_a[i] > k:
        break

sum_b = [0]
for i in range(1,len(b)):
    sum_b.append(sum_b[i-1] + b[i])
    if sum_b[i] > k:
        break

ans = 0
for i in range(len(sum_a)):
    if sum_a[i] > k:
        break
    for j in range(len(sum_b)-1,-1,-1):
        if sum_a[i] + sum_b[j] <= k:
            ans = max(ans, i+j)
            break
print(ans)



Fixed submission:
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
a.insert(0,0)
b.insert(0,0)

sum_a = [0]
for i in range(1,n+1):
    sum_a.append(sum_a[i-1] + a[i])

sum_b = [0]
for i in range(1,m+1):
    sum_b.append(sum_b[i-1] + b[i])

ans = 0
for i in range(n+1):
    if sum_a[i] > k:
        break
    for j in range(m,-1,-1):
        if sum_a[i] + sum_b[j] <= k:
            ans = max(ans, i+j)
            m = j
            break
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
a.insert(0,0)
b.insert(0,0)

sum_a = [0]
for i in range(1,len(a)):
    sum_a.append(sum_a[i-1] + a[i])
    if sum_a[i] > k:
        break

sum_b = [0]
for i in range(1,len(b)):
    sum_b.append(sum_b[i-1] + b[i])
    if sum_b[i] > k:
        break

ans = 0
for i in range(len(sum_a)):
    if sum_a[i] > k:
        break
    for j in range(len(sum_b)-1,-1,-1):
        if sum_a[i] + sum_b[j] <= k:
            ans = max(ans, i+j)
            break
print(ans)



Fixed submission:
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
a.insert(0,0)
b.insert(0,0)

sum_a = [0]
for i in range(1,n+1):
    sum_a.append(sum_a[i-1] + a[i])

sum_b = [0]
for i in range(1,m+1):
    sum_b.append(sum_b[i-1] + b[i])

ans = 0
for i in range(n+1):
    if sum_a[i] > k:
        break
    for j in range(m,-1,-1):
        if sum_a[i] + sum_b[j] <= k:
            ans = max(ans, i+j)
            m = j
            break
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
a.insert(0,0)
b.insert(0,0)

sum_a = [0]
for i in range(1,len(a)):
    sum_a.append(sum_a[i-1] + a[i])
    if sum_a[i] > k:
        break

sum_b = [0]
for i in range(1,len(b)):
    sum_b.append(sum_b[i-1] + b[i])
    if sum_b[i] > k:
        break

ans = 0
for i in range(len(sum_a)):
    if sum_a[i] > k:
        break
    for j in range(len(sum_b)-1,-1,-1):
        if sum_a[i] + sum_b[j] <= k:
            ans = max(ans, i+j)
print(ans)

Fixed submission:
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
a.insert(0,0)
b.insert(0,0)

sum_a = [0]
for i in range(1,n+1):
    sum_a.append(sum_a[i-1] + a[i])

sum_b = [0]
for i in range(1,m+1):
    sum_b.append(sum_b[i-1] + b[i])

ans = 0
for i in range(n+1):
    if sum_a[i] > k:
        break
    for j in range(m,-1,-1):
        if sum_a[i] + sum_b[j] <= k:
            ans = max(ans, i+j)
            m = j
            break
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
a.insert(0,0)

ans = 0
time = 0
for i in range(len(a)):
    tmp = i
    time += a[i]
    if time > k:
        break
    tmp_time = time
    for j in range(len(b)):
        if tmp_time + b[j] <= k:
            tmp_time += b[j]
            tmp += 1
        else:
            break
    ans = max(ans,tmp)
print(ans)


Fixed submission:
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
a.insert(0,0)
b.insert(0,0)

sum_a = [0]
for i in range(1,n+1):
    sum_a.append(sum_a[i-1] + a[i])

sum_b = [0]
for i in range(1,m+1):
    sum_b.append(sum_b[i-1] + b[i])

ans = 0
for i in range(n+1):
    if sum_a[i] > k:
        break
    for j in range(m,-1,-1):
        if sum_a[i] + sum_b[j] <= k:
            ans = max(ans, i+j)
            m = j
            break
print(ans)