Buggy python submission (verdict: Runtime Error):
n,m,k = map(int,input().split())
a = [0]+list(map(int,input().split()))
b = [0]+list(map(int,input().split()))
s = [0]*(n+1)
t = [0]*(m+1)
x = 0
for i in range(n+1):
    s[i] += x + a[i]
    x = s[i]
for i in range(n+1):
    if(s[i] >= k):
        p = i
        break
x = 0
for i in range(m+1):
    t[i] += x + b[i]
    x = t[i]
for i in range(m+1):
    if(t[i] >= k):
        p = max(p,i)
        break
#print(s,t)
while(1):
    f = 0
    for j in range(p-min(p,m),min(p,n)+1):
        #print(j,p-j)
        if(s[j]+t[p-j] <= k):
            #print(j,x-j)
                f = 1
                break
    if(f == 0):
        break
    p += 1
print(p-1)

Fixed submission:
n,m,k = map(int,input().split())
a = [0]+list(map(int,input().split()))
b = [0]+list(map(int,input().split()))
s = [0]*(n+1)
t = [0]*(m+1)
x = 0
for i in range(n+1):
    s[i] += x + a[i]
    x = s[i]
if(s[-1] <= k):
    p = n
else:
    for i in range(n+1):
        if(s[i] >= k):
            p = i
            break
x = 0
for i in range(m+1):
    t[i] += x + b[i]
    x = t[i]
if(t[-1] <= k):
    p = min(p,m)
else:
    for i in range(m+1):
        if(t[i] >= k):
            p = max(p,i)
            break
#print(s,t)
while(1):
    f = 0
    for j in range(p-min(p,m),min(p,n)+1):
        #print(j,p-j)
        if(s[j]+t[p-j] <= k):
            #print(j,x-j)
                f = 1
                break
    if(f == 0):
        break
    p += 1
print(p-1)

Buggy python submission (verdict: Time Limit Exceeded):
n,m,k = map(int,input().split())
a = [0]+list(map(int,input().split()))
b = [0]+list(map(int,input().split()))
s = [0]*(n+1)
t = [0]*(m+1)
x = 0
for i in range(n+1):
    s[i] += x + a[i]
    x = s[i]
x = 0
for i in range(m+1):
    t[i] += x + b[i]
    x = t[i]
#print(s,t)
x = 1
while(1):
#for i in range(30):
    f = 0
    #print(x)
    for j in range(x-min(x,m),min(x,n)+1):
        #print(j,x-j)
        if(s[j]+t[x-j] <= k):
            #print(j,x-j)
                f = 1
                break
    if(f == 0):
        break
    x += 1
print(x-1)

Fixed submission:
n,m,k = map(int,input().split())
a = [0]+list(map(int,input().split()))
b = [0]+list(map(int,input().split()))
s = [0]*(n+1)
t = [0]*(m+1)
x = 0
for i in range(n+1):
    s[i] += x + a[i]
    x = s[i]
if(s[-1] <= k):
    p = n
else:
    for i in range(n+1):
        if(s[i] >= k):
            p = i
            break
x = 0
for i in range(m+1):
    t[i] += x + b[i]
    x = t[i]
if(t[-1] <= k):
    p = min(p,m)
else:
    for i in range(m+1):
        if(t[i] >= k):
            p = max(p,i)
            break
#print(s,t)
while(1):
    f = 0
    for j in range(p-min(p,m),min(p,n)+1):
        #print(j,p-j)
        if(s[j]+t[p-j] <= k):
            #print(j,x-j)
                f = 1
                break
    if(f == 0):
        break
    p += 1
print(p-1)

Buggy python submission (verdict: Time Limit Exceeded):
n,m,k = map(int,input().split())
a = [0]+list(map(int,input().split()))
b = [0]+list(map(int,input().split()))
s = [0]*(n+1)
t = [0]*(m+1)
p = m-1
q = n-1
x = 0
for i in range(n+1):
    s[i] += x + a[i]
    x = s[i]
x = 0
for i in range(m+1):
    t[i] += x + b[i]
    x = t[i]
#print(s,t)
x = 1
while(1):
#for i in range(30):
    f = 0
    #print(x)
    for j in range(x+1):
        if(m>=x-j):
            if(n >= j):
                if(s[j]+t[x-j] <= k):
                    #print(j,x-j)
                    f = 1
                    break
            else:
                break
    if(f == 0):
        break
    x += 1
print(x-1)

Fixed submission:
n,m,k = map(int,input().split())
a = [0]+list(map(int,input().split()))
b = [0]+list(map(int,input().split()))
s = [0]*(n+1)
t = [0]*(m+1)
x = 0
for i in range(n+1):
    s[i] += x + a[i]
    x = s[i]
if(s[-1] <= k):
    p = n
else:
    for i in range(n+1):
        if(s[i] >= k):
            p = i
            break
x = 0
for i in range(m+1):
    t[i] += x + b[i]
    x = t[i]
if(t[-1] <= k):
    p = min(p,m)
else:
    for i in range(m+1):
        if(t[i] >= k):
            p = max(p,i)
            break
#print(s,t)
while(1):
    f = 0
    for j in range(p-min(p,m),min(p,n)+1):
        #print(j,p-j)
        if(s[j]+t[p-j] <= k):
            #print(j,x-j)
                f = 1
                break
    if(f == 0):
        break
    p += 1
print(p-1)