Buggy python submission (verdict: Time Limit Exceeded):
#n = int(input())
n,m,k = [int(z) for z in input().split()]
a = [int(z) for z in input().split()]
b = [int(z) for z in input().split()]
time = 0
x=[0]
y=[0]
#maX = -100000
num = 0
for i in range(n):
      x.append(x[i]+a[i])
for j in range(m):
      y.append(y[j]+b[j])

for i in range(n+1):
      if (x[i]>k):
            break
      for j in range(m+1):
            if (y[j]>k):
                  break
            z = x[i]+y[j]
            if (z<=k):
                  num = max(num,i+j)
                  
print(num)


Fixed submission:
import sys
import bisect
import itertools
import collections
import fractions
import heapq
import math
from operator import mul
from functools import reduce
from functools import lru_cache


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    N, M, K = map(int, readline().split())
    A = list(map(int, readline().split()))
    B = list(map(int, readline().split()))


    nowtime = 0

    Asum = [0]
    Bsum = [0]
    tmp = 0
    for a in A:
        tmp += a
        Asum.append(tmp)
    tmp = 0
    for b in B:
        tmp += b
        Bsum.append(tmp)

    maxbooks = 0
    before = M
    bcount = M
    for acount in range(N+1):
        if Asum[acount] > K:
            continue
        while K < Asum[acount] + Bsum[bcount]:
            bcount -= 1
        maxbooks = max(maxbooks, acount+bcount)

    print(maxbooks)

if __name__ == '__main__':
    solve()

Buggy python submission (verdict: Time Limit Exceeded):
#n = int(input())
n,m,k = [int(z) for z in input().split()]
a = [int(z) for z in input().split()]
b = [int(z) for z in input().split()]
time = 0
x=[0]
y=[0]
#maX = -100000
num = 0
for i in range(n):
      x.append(x[i]+a[i])
for j in range(m):
      y.append(y[j]+b[j])

for i in range(n+1):
      for j in range(m+1):
            z = x[i]+y[j]
            if (z<=k):
                  num = max(num,i+j)
                  
print(num)


Fixed submission:
import sys
import bisect
import itertools
import collections
import fractions
import heapq
import math
from operator import mul
from functools import reduce
from functools import lru_cache


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    N, M, K = map(int, readline().split())
    A = list(map(int, readline().split()))
    B = list(map(int, readline().split()))


    nowtime = 0

    Asum = [0]
    Bsum = [0]
    tmp = 0
    for a in A:
        tmp += a
        Asum.append(tmp)
    tmp = 0
    for b in B:
        tmp += b
        Bsum.append(tmp)

    maxbooks = 0
    before = M
    bcount = M
    for acount in range(N+1):
        if Asum[acount] > K:
            continue
        while K < Asum[acount] + Bsum[bcount]:
            bcount -= 1
        maxbooks = max(maxbooks, acount+bcount)

    print(maxbooks)

if __name__ == '__main__':
    solve()

Buggy python submission (verdict: Runtime Error):
#n = int(input())
n,m,k = [int(z) for z in input().split()]
a = [int(z) for z in input().split()]
b = [int(z) for z in input().split()]
time = 0
i = j = 0
while (time<=k and i<n and j<m):
      #print(i,j,time)
      if (a[i]<b[j]):
            if (time+a[i]<=k):
                  time += a[i]
                  i+=1
            else:
                  break
      else:
            if (time+b[j]<=k):
                  time += b[j]
                  j+=1
            else:
                  break
while (i<n and time<=k):
      if (time+a[i]<=k):
                  time += a[i]
                  i+=1
      else:
            break
while (j<n and time<=k):
      if (time+b[j]<=k):
                  time += b[j]
                  j+=1
      else:
            break
print(i+j)


Fixed submission:
import sys
import bisect
import itertools
import collections
import fractions
import heapq
import math
from operator import mul
from functools import reduce
from functools import lru_cache


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    N, M, K = map(int, readline().split())
    A = list(map(int, readline().split()))
    B = list(map(int, readline().split()))


    nowtime = 0

    Asum = [0]
    Bsum = [0]
    tmp = 0
    for a in A:
        tmp += a
        Asum.append(tmp)
    tmp = 0
    for b in B:
        tmp += b
        Bsum.append(tmp)

    maxbooks = 0
    before = M
    bcount = M
    for acount in range(N+1):
        if Asum[acount] > K:
            continue
        while K < Asum[acount] + Bsum[bcount]:
            bcount -= 1
        maxbooks = max(maxbooks, acount+bcount)

    print(maxbooks)

if __name__ == '__main__':
    solve()

Buggy python submission (verdict: Runtime Error):
#n = int(input())
n,m,k = [int(z) for z in input().split()]
a = [int(z) for z in input().split()]
b = [int(z) for z in input().split()]
time = 0
i = j = 0
while (time<=k and i<n and j<m):
      if (a[i]>b[j]):
            if (time+a[i]<=k):
                  time += a[i]
                  i+=1
            else:
                  break
      else:
            if (time+b[j]<=k):
                  time += b[j]
                  j+=1
            else:
                  break
while (i<n and time<=k):
      if (time+a[i]<=k):
                  time += a[i]
                  i+=1
      else:
            break
while (j<n and time<=k):
      if (time+b[j]<=k):
                  time += b[j]
                  j+=1
      else:
            break
print(i+j)


Fixed submission:
import sys
import bisect
import itertools
import collections
import fractions
import heapq
import math
from operator import mul
from functools import reduce
from functools import lru_cache


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    N, M, K = map(int, readline().split())
    A = list(map(int, readline().split()))
    B = list(map(int, readline().split()))


    nowtime = 0

    Asum = [0]
    Bsum = [0]
    tmp = 0
    for a in A:
        tmp += a
        Asum.append(tmp)
    tmp = 0
    for b in B:
        tmp += b
        Bsum.append(tmp)

    maxbooks = 0
    before = M
    bcount = M
    for acount in range(N+1):
        if Asum[acount] > K:
            continue
        while K < Asum[acount] + Bsum[bcount]:
            bcount -= 1
        maxbooks = max(maxbooks, acount+bcount)

    print(maxbooks)

if __name__ == '__main__':
    solve()