Buggy python submission (verdict: Time Limit Exceeded):
import random
n, m, k = map(int, input().split())
# n, m, k = random.randint(1, 10**5), random.randint(1, 10**5), random.randint(10**8, 10**9)
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
# a_list = [random.randint(1, 10**8) for i in range(n)]
# b_list = [random.randint(1, 10**7) for i in range(m)]
# print(n,m,k)
# print(a_list[0], b_list[0])
a_sum = [0]
b_sum = [0]
for i in range(1, max(n+1, m+1)):
    if i < n+1:
        a_sum.append(a_sum[i-1] + a_list[i-1])
    if i < m+1:
        b_sum.append(b_sum[i-1] + b_list[i-1])

ans = 0
for i in range(n+1):
    if a_sum[i] > k:
        break
    else:
        j = 0
        while j <= m and b_sum[j] <= k - a_sum[i]:
            j += 1
        j -= 1
    ans = max(ans, i+j)
        
print(ans)
# print(n+m) 

Fixed submission:
import random
n, m, k = map(int, input().split())
# n, m, k = random.randint(1, 10**5), random.randint(1, 10**5), random.randint(10**8, 10**9)
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
# a_list = [random.randint(1, 10**3) for i in range(n)]
# b_list = [random.randint(1, 10**3) for i in range(m)]
# print(n,m,k)
# print(a_list[0], b_list[0])
a_sum = [0]
b_sum = [0]
max_a = 0
for i in range(1, max(n+1, m+1)):
    if i < n+1:
        a_sum.append(a_sum[i-1] + a_list[i-1])
        if a_sum[i] <= k:
            max_a = i
    if i < m+1:
        b_sum.append(b_sum[i-1] + b_list[i-1])

ans = 0
j = m
for i in range(0, max_a+1):
    while b_sum[j] > k - a_sum[i]:
        j -= 1
    ans = max(ans, i+j)
        
print(ans)
# print(n+m)

Buggy python submission (verdict: Time Limit Exceeded):
import random
n, m, k = map(int, input().split())
# n, m, k = random.randint(1, 10**5), random.randint(1, 10**5), random.randint(10**8, 10**9)
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
# a_list = [random.randint(1, 10**8) for i in range(n)]
# b_list = [random.randint(1, 10**7) for i in range(m)]
# print(n,m,k)
# print(a_list[0], b_list[0])
a_sum = [0]
b_sum = [0]
for i in range(1, max(n+1, m+1)):
    if i < n+1:
        a_sum.append(a_sum[i-1] + a_list[i-1])
    if i < m+1:
        b_sum.append(b_sum[i-1] + b_list[i-1])

ans = 0
for i in range(n+1):
    if a_sum[i] > k:
        break
    else:
        j = 0
        while j <= m and b_sum[j] <= k - a_sum[i]:
            j += 1
        j -= 1
    ans = max(ans, i+j)
        
print(ans)
# print(n+m) 

Fixed submission:
import random
n, m, k = map(int, input().split())
# n, m, k = random.randint(1, 10**5), random.randint(1, 10**5), random.randint(10**8, 10**9)
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
# a_list = [random.randint(1, 10**3) for i in range(n)]
# b_list = [random.randint(1, 10**3) for i in range(m)]
# print(n,m,k)
# print(a_list[0], b_list[0])
a_sum = [0]
b_sum = [0]
max_a = 0
for i in range(1, max(n+1, m+1)):
    if i < n+1:
        a_sum.append(a_sum[i-1] + a_list[i-1])
        if a_sum[i] <= k:
            max_a = i
    if i < m+1:
        b_sum.append(b_sum[i-1] + b_list[i-1])

ans = 0
j = m
for i in range(0, max_a+1):
    while b_sum[j] > k - a_sum[i]:
        j -= 1
    ans = max(ans, i+j)
        
print(ans)
# print(n+m)

Buggy python submission (verdict: Time Limit Exceeded):
import random
n, m, k = map(int, input().split())
# n, m, k = random.randint(1, 10**5), random.randint(1, 10**5), random.randint(10**7, 10**8)
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
# a_list = [random.randint(1, 10**2) for i in range(n)]
# b_list = [random.randint(1, 10**2) for i in range(m)]
# print(n,m,k)
# print(a_list[0], b_list[0])
a_sum = [0]
b_sum = [0]
for i in range(1, max(n+1, m+1)):
    if i < n+1:
        a_sum.append(a_sum[i-1] + a_list[i-1])
    if i < m+1:
        b_sum.append(b_sum[i-1] + b_list[i-1])

ans = 0
for i in range(n+1):
    if a_sum[i] > k:
        break
    else:
        j = m
        while b_sum[j] > k - a_sum[i]:
            j -= 1
    ans = max(ans, i+j)
        
print(ans)
# print(n+m) 

Fixed submission:
import random
n, m, k = map(int, input().split())
# n, m, k = random.randint(1, 10**5), random.randint(1, 10**5), random.randint(10**8, 10**9)
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
# a_list = [random.randint(1, 10**3) for i in range(n)]
# b_list = [random.randint(1, 10**3) for i in range(m)]
# print(n,m,k)
# print(a_list[0], b_list[0])
a_sum = [0]
b_sum = [0]
max_a = 0
for i in range(1, max(n+1, m+1)):
    if i < n+1:
        a_sum.append(a_sum[i-1] + a_list[i-1])
        if a_sum[i] <= k:
            max_a = i
    if i < m+1:
        b_sum.append(b_sum[i-1] + b_list[i-1])

ans = 0
j = m
for i in range(0, max_a+1):
    while b_sum[j] > k - a_sum[i]:
        j -= 1
    ans = max(ans, i+j)
        
print(ans)
# print(n+m)

Buggy python submission (verdict: Runtime Error):
import random
n, m, k = map(int, input().split())
# n, m, k = random.randint(1, 10**5), random.randint(1, 10**5), random.randint(10**7, 10**8)
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
# a_list = [random.randint(1, 10**2) for i in range(n)]
# b_list = [random.randint(1, 10**2) for i in range(m)]
# print(n,m,k)
# print(a_list[0], b_list[0])
a_sum = [0]
b_sum = [0]
for i in range(1, max(n+1, m+1)):
    if i < n+1:
        a_sum.append(a_sum[i-1] + a_list[i-1])
    if i < m+1:
        b_sum.append(b_sum[i-1] + b_list[i-1])

ans = 0
for i in range(n+1):
    if a_sum[i] > k:
        break
    else:
        j = m
        while b_sum[j] <= k - a_sum[i]:
            j -= 1
    ans = max(ans, i+j)
        
print(ans)
# print(n+m) 

Fixed submission:
import random
n, m, k = map(int, input().split())
# n, m, k = random.randint(1, 10**5), random.randint(1, 10**5), random.randint(10**8, 10**9)
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
# a_list = [random.randint(1, 10**3) for i in range(n)]
# b_list = [random.randint(1, 10**3) for i in range(m)]
# print(n,m,k)
# print(a_list[0], b_list[0])
a_sum = [0]
b_sum = [0]
max_a = 0
for i in range(1, max(n+1, m+1)):
    if i < n+1:
        a_sum.append(a_sum[i-1] + a_list[i-1])
        if a_sum[i] <= k:
            max_a = i
    if i < m+1:
        b_sum.append(b_sum[i-1] + b_list[i-1])

ans = 0
j = m
for i in range(0, max_a+1):
    while b_sum[j] > k - a_sum[i]:
        j -= 1
    ans = max(ans, i+j)
        
print(ans)
# print(n+m)

Buggy python submission (verdict: Runtime Error):
n, m, k = map(int, input().split())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
a_index = 0
b_index = 0
count = 0

def nap(a_index, b_index, time, count):
    if a_index >= len(a_list) and b_index >= len(b_list):
        return count
    else:
        if a_index >= len(a_list) or a_list[a_index]>time:
            nap1 = count
        else:
            nap1 = nap(a_index+1, b_index, time-a_list[a_index], count+1)
        if b_index >= len(b_list) or b_list[b_index]>time:
            nap2 = count
        else:
            nap2 = nap(a_index, b_index+1, time-b_list[b_index], count+1)
    return max(nap1, nap2)

print(nap(0, 0, k, 0))


Fixed submission:
import random
n, m, k = map(int, input().split())
# n, m, k = random.randint(1, 10**5), random.randint(1, 10**5), random.randint(10**8, 10**9)
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
# a_list = [random.randint(1, 10**3) for i in range(n)]
# b_list = [random.randint(1, 10**3) for i in range(m)]
# print(n,m,k)
# print(a_list[0], b_list[0])
a_sum = [0]
b_sum = [0]
max_a = 0
for i in range(1, max(n+1, m+1)):
    if i < n+1:
        a_sum.append(a_sum[i-1] + a_list[i-1])
        if a_sum[i] <= k:
            max_a = i
    if i < m+1:
        b_sum.append(b_sum[i-1] + b_list[i-1])

ans = 0
j = m
for i in range(0, max_a+1):
    while b_sum[j] > k - a_sum[i]:
        j -= 1
    ans = max(ans, i+j)
        
print(ans)
# print(n+m)