Problem:


Score : 300 points

Problem Statement

We have two desks: A and B. Desk A has a vertical stack of N books on it, and Desk B similarly has M books on it.

It takes us A_i minutes to read the i-th book from the top on Desk A (1 \leq i \leq N), and B_i minutes to read the i-th book from the top on Desk B (1 \leq i \leq M).

Consider the following action:

Choose a desk with a book remaining, read the topmost book on that desk, and remove it from the desk.

How many books can we read at most by repeating this action so that it takes us at most K minutes in total? We ignore the time it takes to do anything other than reading.

Constraints

1 \leq N, M \leq 200000

1 \leq K \leq 10^9

1 \leq A_i, B_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M K
A_1 A_2 \ldots A_N
B_1 B_2 \ldots B_M

Output

Print an integer representing the maximum number of books that can be read.

Sample Input 1

3 4 240
60 90 120
80 150 80 150

Sample Output 1

3

In this case, it takes us 60, 90, 120 minutes to read the 1-st, 2-nd, 3-rd books from the top on Desk A, and 80, 150, 80, 150 minutes to read the 1-st, 2-nd, 3-rd, 4-th books from the top on Desk B, respectively.

We can read three books in 230 minutes, as shown below, and this is the maximum number of books we can read within 240 minutes.

Read the topmost book on Desk A in 60 minutes, and remove that book from the desk.

Read the topmost book on Desk B in 80 minutes, and remove that book from the desk.

Read the topmost book on Desk A in 90 minutes, and remove that book from the desk.

Sample Input 2

3 4 730
60 90 120
80 150 80 150

Sample Output 2

7

Sample Input 3

5 4 1
1000000000 1000000000 1000000000 1000000000 1000000000
1000000000 1000000000 1000000000 1000000000

Sample Output 3

0

Watch out for integer overflows.



Sample input:
3 4 240
60 90 120
80 150 80 150


Sample output:
3

Submission status: Time Limit Exceeded

Solution code:
n, m, k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ans = 0
a_sum = [0] * (n+1)
b_sum = [0] * (m+1)

for i in range(n):
  a_sum[i+1] += a_sum[i] + a[i]
for j in range(m):
  b_sum[j+1] += b_sum[j] + b[j]

for i in range(n+1):
  if a_sum[i] > k:
    break
  for j in range(m+1):
    if a_sum[i] + b_sum[j] <= k and i + j > ans:
      ans = i + j
    if a_sum[i] + b_sum[j] > k:
      break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, m, k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ans = 0
for i in range(n+1):
  if sum(a[:i]) > k:
    break
  for j in range(m+1):
    time = sum(a[:i]) + sum(b[:j])
    if time <= k and i + j > ans:
      ans = i + j
    if time > k:
      break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, m, k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ans = 0
for i in range(n+1):
  if sum(a[:i]) > k:
    continue
  for j in range(m+1):
    time = sum(a[:i]) + sum(b[:j])
    if time <= k and i + j > ans:
      ans = i + j
    if time > k:
      break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, m, k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ans = 0
for i in range(n+1):
  for j in range(m+1):
    time = sum(a[:i]) + sum(b[:j])
    if time <= k and i + j > ans:
      ans = i + j
    if time > k:
      break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, m, k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ans = 0
for i in range(n+1):
  for j in range(m+1):
    time = sum(a[:i]) + sum(b[:j])
    if time <= k and i + j > ans:
      ans = i + j
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, M, K = map(int, input().split(' '))
A_ls = [0] + list(map(int, input().split(' ')))
B_ls = [0] + list(map(int, input().split(' ')))

for i in range(1, N + 1):
    A_ls[i] += A_ls[i - 1]
for i in range(1, M + 1):
    B_ls[i] += B_ls[i - 1]

a_cnt, b_cnt, rst = -1, -1, 0
for i in range(N + 1):
    if A_ls[i] > K:
        break
    for j in range(M + 1):
        if A_ls[i] + B_ls[j] > K:
            break
        rst = max(rst, i + j)
print(rst)

Submission status: Time Limit Exceeded

Solution code:
N,M,K=map(int,input().split())
A,B=[0],[0]
A+=map(int,input().split())
B+=map(int,input().split())

for i in range(1,N+1):
    A[i]+=A[i-1]
for i in range(1,M+1):
    B[i]+=B[i-1]

ans=0
for i in range(N+1):
    if A[i]>K:
        break
    for j in range(M+1):
        if A[i]+B[j]>K:
            break
        ans=max(ans,i+j)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,M,K=map(int,input().split())
A,B=[0],[0]
A+=map(int,input().split())
B+=map(int,input().split())

for i in range(1,N+1):
    A[i]+=A[i-1]
for i in range(1,M+1):
    B[i]+=B[i-1]

ans=0
for i in range(N+1):
    for j in range(M+1):
        x=A[i]+B[j]
        if x>K:
            break
        ans=max(ans,i+j)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,M,K=map(int,input().split())
A=[0]+list(map(int,input().split()))
B=[0]+list(map(int,input().split()))

if N!=1:
    for i in range(1,N+1):
        A[i]+=A[i-1]
if M!=1:
    for i in range(1,M+1):
        B[i]+=B[i-1]

t,jm=0,M
for i in range(N+1):
   if A[i]>K:
       break

   for j in reversed(range(jm+1)):
        if A[i]+B[j]<=K and t<=i+j:
            t=i+j
            jm=j
            break
print(t)

Submission status: Time Limit Exceeded

Solution code:
N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A.insert(0,0)
B.insert(0,0)
for i in range(1,N+1):
  A[i] += A[i-1]
for i in range(1,M+1):
  B[i] += B[i-1]
MAX_K = 10 ** 9
MAX_DEPTH = N+M
data = [0] * MAX_DEPTH

for i in range(1, N+M+1):
  value = MAX_K
  for aNum in range(i+1):
    bNum = i - aNum
    if aNum <= N and bNum <= M:
      tempValue = A[aNum] + B[bNum]
      if tempValue < value:
        value = tempValue
  if value > K:
    print(i-1)
    exit()
print(N+M)

Submission status: Time Limit Exceeded

Solution code:
N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A.insert(0,0)
B.insert(0,0)
for i in range(1,N+1):
  A[i] += A[i-1]
for i in range(1,M+1):
  B[i] += B[i-1]
MAX_K = 10 ** 9
MAX_DEPTH = N+M
data = [0] * MAX_DEPTH

for i in range(1, N+M+1):
  value = MAX_K
  for aNum in range(i+1):
    bNum = i - aNum
    if aNum <= N and bNum <= M:
      tempValue = A[aNum] + B[bNum]
      if tempValue < value:
        value = tempValue
  if value > K:
    print(i-1)
    exit()
print(N+M)

Submission status: Time Limit Exceeded

Solution code:
n,m,k=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
a,b=[0],[0]
for i in range(n):
  a.append(a[i]+A[i])
for i in range(m):
  b.append(b[i]+B[i])
ans=0
book=0
for i in range(n+1):
  if a[i]>k:
    break
  for j in range(m+1):
    if a[i]+b[j]<=k:
      book=i+j
      if book>ans:
        ans = book
    else:
      break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,M,K=map(int,input().split())
A=[0]+list(map(int,input().split()))
B=[0]+list(map(int,input().split()))

if N!=1:
    for i in range(1,N+1):
        A[i]+=A[i-1]
if M!=1:
    for i in range(1,M+1):
        B[i]+=B[i-1]

t,jm=0,M
for i in range(N+1):
    for j in reversed(range(jm+1)):
        if A[i]+B[j]<=K and t<=i+j:
            t=i+j
            jm=j
            break
print(t)

Submission status: Time Limit Exceeded

Solution code:
n,m,k=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
a,b=[0],[0]
for i in range(n):
  a.append(a[i]+A[i])
for i in range(m):
  b.append(b[i]+B[i])
ans=0
book=0
for i in range(n+1):
  for j in range(m+1):
    if a[i]+b[j]<=k:
      book=i+j
      if book>ans:
        ans = book
    else:
      break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,M,K=map(int,input().split())
A=[0]+list(map(int,input().split()))
B=[0]+list(map(int,input().split()))

if N!=1:
    for i in range(1,N+1):
        A[i]+=A[i-1]
if M!=1:
    for i in range(1,M+1):
        B[i]+=B[i-1]

t=0
for i in range(N+1):
    for j in range(M+1):
        if A[i]+B[j]<=K and t<=i+j:
            t=i+j
print(t)

Submission status: Time Limit Exceeded

Solution code:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

max_num = 0
j = 0
j_max = M
# A_sums=[0]
# B_sums=[0]
# for i in range(N):
#     A_sums.append(A_sums[i]+A[i])
# for i in range(M):
#     B_sums.append(B_sums[i]+B[i])


for i in range(N + 1):
    j = 0
    if sum(A[:i])>K:
        break
    while sum(A[:i]) + sum(B[:j_max]) > K:
        j_max -=1

    max_num = max(max_num, i + j_max)
print(max_num)

Submission status: Time Limit Exceeded

Solution code:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

max_num = 0
j = 0
j_max = M + 1
A_sums=[0]
B_sums=[0]
for i in range(N):
    A_sums.append(A_sums[i]+A[i])
for i in range(M):
    B_sums.append(B_sums[i]+B[i])


for i in range(N + 1):
    j = 0
    if A_sums[i]>K:
        break
    while j < j_max:
        if A_sums[i] + B_sums[j] > K:
            j_max = j
            break

        max_num = max(max_num, i + j)
        j += 1
print(max_num)

Submission status: Time Limit Exceeded

Solution code:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

max_num = 0
j = 0
j_max = M + 1
A_sums=[0]
B_sums=[0]
for i in range(N):
    A_sums.append(A_sums[i]+A[i])
for i in range(M):
    B_sums.append(B_sums[i]+B[i])


for i in range(N + 1):
    j = 0
    while j < j_max:

        if A_sums[i] + B_sums[j] > K:
            j_max = j
            break

        max_num = max(max_num, i + j)
        j += 1
print(max_num)

Submission status: Time Limit Exceeded

Solution code:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

max_num = 0
j = 0
j_max = M + 1
A_sums=[sum(A[:i]) for i in range(N+1)]
B_sums=[sum(B[:i]) for i in range(M+1)]

for i in range(N + 1):
    j = 0
    while j < j_max:

        if A_sums[i] + B_sums[j] > K:
            j_max = j
            break

        max_num = max(max_num, i + j)
        j += 1
print(max_num)

Submission status: Time Limit Exceeded

Solution code:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

max_num = 0
j = 0
j_max = M + 1
for i in range(N + 1):
    j = 0
    while j < j_max:
        if sum(A[:i]) + sum(B[:j]) > K:
            j_max = j
            break

        max_num = max(max_num, i + j)
        j += 1
print(max_num)

Submission status: Time Limit Exceeded

Solution code:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

b2=[]
b2.append(0)
for i in range(1,m+1):
  b2.append(b2[i-1]+b[i-1])
a.insert(0,0)
cnt=0
a_sum=0
for i in range(n+1):
  j=m
  a_sum+=a[i]
  while True:
    if k>=a_sum+b2[j]:
      cnt=max(cnt,i+j)
      break
    j-=1
    if j <0:
      break
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n,m,k = map(int,input().split())
book_list = list(map(int,input().split()))
book_list.extend(list(map(int,input().split())))
book_list.sort()
count=0
readTime=0
for i in range(n+m):
    if readTime+book_list[0]<=k:
        count+=1
        readTime+=book_list[0]
        del book_list[0]
    else:
        break
print(count)

Submission status: Time Limit Exceeded

Solution code:
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
aa = [0]
for i in range(n):
    aa.append(aa[-1]+a[i])
bb = [0]
for i in range(m):
    bb.append(bb[-1]+b[i])
ans = 0
for i in range(n+1):
    if aa[i] > k:
        break
    j = m
    while aa[i] + bb[j] > k and j > 0:
        j -= 1
    ans = max(ans, i+j)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
aa = [0]
for i in a:
    aa.append(aa[-1]+i)
bb = [0]
for i in b:
    bb.append(bb[-1]+i)
ans = 0
for i in range(n+1):
    if aa[i] > k:
        break
    j = m
    while aa[i] + bb[j] > k and j > 0:
        j -= 1
    ans = max(ans, i+j)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
aa = [0]
for i in a:
    aa.append(aa[-1]+i)
bb = [0]
for i in b:
    bb.append(bb[-1]+i)
ans = 0
for i in range(n+1):
    if aa[i] > k:
        break
    for j in range(m+1):
        if aa[i]+bb[m-j] <= k:
            ans = max(ans, i+m-j)
            break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
aa = [0]
for i in a:
    aa.append(aa[-1]+i)
bb = [0]
for i in b:
    bb.append(bb[-1]+i)
ans = 0
for i in range(n+1):
    if aa[i] > k:
        break
    for j in range(m+1):
        if aa[i]+bb[j] <= k:
            tmp = i+j
        else:
            break
    ans = max(ans, tmp)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,m,k=map(int,input().split())
A=list(map(int, input().split()))
B=list(map(int, input().split()))
ans=0
a, b=[0], [0]
for i in range(n):
    a.append(a[i]+A[i])
for i in range(m):
    b.append(b[i]+B[i])
for i in range(n+1):
    if k<a[i]:
        break
    j=m
    while b[j]>k-a[i]:
        j-=1
    ans=max(ans,i+j)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
aa = [0]
bb = [0]
for i in a:
    aa.append(aa[-1]+i)
for i in b:
    bb.append(bb[-1]+i)
sub = []
for i in range(len(aa)):
    if aa[i] > k:
        break
    for j in range(len(bb)):
        if aa[i]+bb[j] <= k:
            tmp = i+j
        else:
            break
    sub.append(tmp)
print(max(sub))

Submission status: Time Limit Exceeded

Solution code:
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
aa = [0]
bb = [0]
sub = []
for i in a:
    aa.append(aa[-1]+i)
for i in b:
    bb.append(bb[-1]+i)
for i in range(len(aa)):
    if aa[i] > k:
        break
    for j in range(len(bb)):
        if aa[i]+bb[j] <= k:
            tmp = i+j
    sub.append(tmp)
print(max(sub))

Submission status: Time Limit Exceeded

Solution code:
INF = 10**18
N, M, K = map(int, input().split())
tmp = 0
k = [K]
for a in map(int, input().split()):
  K -= a
  if K >= 0:
    tmp += 1
    k += [K]
  else:
    break
ans = max(tmp, 0)
A_index = tmp
B = list(map(int, input().split()))
b_num = len(B) - 1
b = B.pop(0)
while True:
  if b <= k[A_index]:
    tmp += 1
    ans = max(ans, tmp)
    if b_num == 0:
      break
    else:
      b += B.pop(0)
      b_num -= 1
  else:
    tmp -= 1
    A_index -= 1
    if A_index < 0:
      break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n,m,k=map(int,input().split())
A=[0]+list(map(int, input().split()))
B=[0]+list(map(int, input().split()))
ans=0
a=np.cumsum(np.array(A))
b=np.cumsum(np.array(B))
for i in range(n+1):
    if k<a[i]:
        break
    j=m
    while b[j]>k-a[i]:
        j-=1
    ans=max(ans,i+j)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n,m,k=map(int,input().split())
A=[0]+list(map(int, input().split()))
B=[0]+list(map(int, input().split()))
ans=0
a=np.cumsum(np.array(A)).tolist()
b=np.cumsum(np.array(B)).tolist()
for i in range(n+1):
    if k<a[i]:
        break
    j=m
    while b[j]>k-a[i]:
        j-=1
    ans=max(ans,i+j)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n,m,k=map(int,input().split())
A=[0]+list(map(int, input().split()))
B=[0]+list(map(int, input().split()))
ans=0
a=np.cumsum(np.array(A))
b=np.cumsum(np.array(B))
for i in range(n+1):
    if k>=a[i]:
        j=m
        while b[j]>k-a[i]:
            j-=1
        ans=max(ans,i+j)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
from collections import deque
n,m,k=map(int,input().split())
A=[0]+list(map(int, input().split()))
B=[0]+list(map(int, input().split()))
ans=0
a=np.cumsum(np.array(A)).tolist()
b=np.cumsum(np.array(B)).tolist()
for i in range(n+1):
    if k>=a[i]:
        j=m
        while b[j]>k-a[i]:
            j-=1
        ans=max(ans,i+j)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n, m, k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
a = [0] + [i for i in itertools.accumulate(a) if i <= k]
b = [0] + [i for i in itertools.accumulate(b) if i <= k]
print(max([i+j for i in range(len(a)) for j in range(len(b)) if a[i]+b[j] <= k]))

Submission status: Time Limit Exceeded

Solution code:
from itertools import permutations

N, M, K = map(int, input().split())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

l = set(permutations('A'*N+'B'*M, N+M))

cnt_list = []

for i in l:
    time = 0
    cnt = 0
    indA = 0
    indB = 0
    for n in range(N+M):
        if i[n] == 'A':
            time += A[indA]
            indA += 1
        else:
            time += B[indB]
            indB += 1
        if time > K:
            break
        cnt += 1
    cnt_list.append(cnt)

print(max(cnt_list))

Submission status: Time Limit Exceeded

Solution code:
import math
def facts(n):
    ans = []
    for  i in range(1, int(math.sqrt(n)+1)):
        if(n%i==0):
            ans.append(i)
            ans.append(n//i)
    ans = sorted(list(dict.fromkeys(ans)))
    if(ans[-1]==n):
        ans = ans[:-1]
    return ans


n, m,k  = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
pa  = [0]
pb = [0]
ans = 0
for i in range(n):
    pa.append(a[i]+pa[i])
for i in range(m):
    pb.append(b[i]+pb[i])
for c in range(n+1):
    tmp=pa[c]
    if(tmp > k):
        break
    else:
        for d in range(m+1):
            if(pb[d] <= k-tmp):
                ans = max(ans, c+d)
            else:
                break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import accumulate

n, m, k = map(int, input().split())
(*a,) = accumulate(map(int, input().split()))
(*b,) = accumulate(map(int, input().split()))
a = (0,) + tuple(i for i in a if i <= k)
b = (0,) + tuple(i for i in b if i <= k)
ans = 0
for i in range(len(a)):
    tmp = k - a[i]
    for j in range(len(b) - 1, -1, -1):
        if b[j] <= tmp:
            ans = max(ans, i + j)
            break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import accumulate

n, m, k = map(int, input().split())
(*a,) = accumulate(map(int, input().split()))
(*b,) = accumulate(map(int, input().split()))
a = (0,) + tuple(i for i in a if i <= k)
b = (0,) + tuple(i for i in b if i <= k)
ans = set()
for i in range(len(a)):
    tmp = k - a[i]
    for j in range(len(b) - 1, -1, -1):
        if b[j] <= tmp:
            ans.add(i + j)
            break
print(max(ans))

Submission status: Time Limit Exceeded

Solution code:
from itertools import accumulate

n, m, k = map(int, input().split())
(*a,) = accumulate(map(int, input().split()))
(*b,) = accumulate(map(int, input().split()))
a = (0,) + tuple(i for i in a if i <= k)
b = (0,) + tuple(i for i in b if i <= k)
ans = set()
for i in range(len(a)):
    tmp = k - a[i]
    for j in range(len(b) - 1, -1, -1):
        if b[j] <= tmp:
            ans.add(i + j)
            break
print(max(ans))

Submission status: Time Limit Exceeded

Solution code:
l1 = input()
l2 = input()
l3 = input()

n, m, k = map(int, l1.split(' '))
a_l = list(map(int, l2.split(' ')))
b_l = list(map(int, l3.split(' ')))


a_sum = [0]
for a in a_l:
    a_sum.append(a_sum[-1] + a)
    
    if a_sum[-1] >= k:
        break
    
b_sum = [0]
for b in b_l:
    b_sum.append(b_sum[-1] + b)

    if b_sum[-1] >= k:
        break

max_num = 0
for i, a in enumerate(a_sum):
    for j, b in enumerate(b_sum):
        if a + b > k:
            break
        
        if i + j > max_num:
            max_num = i + j
        
    
print(max_num)

Submission status: Time Limit Exceeded

Solution code:
l1 = input()
l2 = input()
l3 = input()

n, m, k = map(int, l1.split(' '))
a_l = list(map(int, l2.split(' ')))
b_l = list(map(int, l3.split(' ')))

max_num = 0

for i in range(len(a_l) + 1):
    a_total = sum(a_l[:i])
    
    if a_total > k:
        break
    else:
        if max_num < i:
            max_num = i
    for j in range(len(b_l) + 1):
        b_total = sum(b_l[:j])
        
        if a_total + b_total > k:
            break
        else:
            if max_num < i + j:
                max_num = i + j
        

print(max_num)

Submission status: Time Limit Exceeded

Solution code:
N, M, K = map(int, input().split())

A = list(map(int, input().split()))
B = list(map(int, input().split()))

a = [0]
b = [0]
ans = 0

for i in range(N):
    a.append(a[i] + A[i])
    #print(a)

for j in range(M):
    b.append(b[j] + B[j])
    #print(b)

for i in range(N+1):
    for j in range(M+1):
        if a[i] + b[j] > K:
            break
        #print('{} + {} = {}'.format(i, j, i+j))
        ans = max(ans, i + j)


print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,M,K = list(map(int,input().strip().split(" ")))
A = list(map(int,input().strip().split(" ")))
B = list(map(int,input().strip().split(" ")))
totalA = [0]
for a in A:
  totalA.append(max(totalA)+a)
totalB = [0]
for b in B:
  totalB.append(max(totalB)+b)
All = []
for a,ta in enumerate(totalA):
  for b,tb in enumerate(totalB):
    if ta+tb <= K:
    	All.append(a+b)
print(max(All))

Submission status: Time Limit Exceeded

Solution code:
N,M,K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

A_accumulate_cost = [0]
lastCost = 0
for i in range(N):
    lastCost += A[i]
    A_accumulate_cost.append(lastCost)

B_accumulate_cost = [0]
lastCost = 0
for i in range(M):
    lastCost += B[i]
    B_accumulate_cost.append(lastCost)

max_num = 0
for i in range(N+1):
    A_cost = A_accumulate_cost[i]
    if (A_cost > K):
        break

    for j in range(M, -1, -1):
        if (A_cost + B_accumulate_cost[j] <= K):
            if (i + j > max_num):
                max_num = i+j
            break

print(max_num)

Submission status: Time Limit Exceeded

Solution code:
N,M,K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

A_accumulate_cost = [0]
lastCost = 0
for i in range(N):
    lastCost += A[i]
    A_accumulate_cost.append(lastCost)

B_accumulate_cost = [0]
lastCost = 0
for i in range(M):
    lastCost += B[i]
    B_accumulate_cost.append(lastCost)

max_num = 0
for i in range(N, -1, -1):
    A_cost = A_accumulate_cost[i]
    if (A_cost > K):
        continue

    for j in range(M, -1, -1):
        if (A_cost + B_accumulate_cost[j] <= K):
            if (i + j > max_num):
                max_num = i+j
            break

print(max_num)

Submission status: Time Limit Exceeded

Solution code:
N,M,K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

# print("N=",N)
# print("M=",M)
# print("K=",K)
# print("A=",A)
# print("B=",B)

A_accumulate_cost = [0]
lastCost = 0
for i in range(N):
    lastCost += A[i]
    A_accumulate_cost.append(lastCost)
    if(lastCost > K):
        break

B_accumulate_cost = [0]
lastCost = 0
for i in range(M):
    lastCost += B[i]
    B_accumulate_cost.append(lastCost)
    if(lastCost > K):
        break

# print(A_accumulate_cost)
# print(B_accumulate_cost)

max_num = 0
for i in range(0,N+1):
    A_cost = A_accumulate_cost[i]
    if (A_cost > K):
        break

    for j in range(0,M+1):
        if (A_cost + B_accumulate_cost[j] > K):
            break

        if( i+j > max_num):
            max_num = i+j

print(max_num)

Submission status: Time Limit Exceeded

Solution code:
N,M,K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

# print("N=",N)
# print("M=",M)
# print("K=",K)
# print("A=",A)
# print("B=",B)

A_accumulate_cost = [0]
lastCost = 0
for i in range(N):
    lastCost += A[i]
    A_accumulate_cost.append(lastCost)

B_accumulate_cost = [0]
lastCost = 0
for i in range(M):
    lastCost += B[i]
    B_accumulate_cost.append(lastCost)

# print(A_accumulate_cost)
# print(B_accumulate_cost)

max_num = 0
for i in range(0,N+1):
    if (A_accumulate_cost[i] > K):
        break

    for j in range(0,M+1):
        if (A_accumulate_cost[i] + B_accumulate_cost[j] > K):
            break

        if( i+j > max_num):
            max_num = i+j

print(max_num)

Submission status: Time Limit Exceeded

Solution code:
import itertools

n, m, k = map(int, input().split())
a_books = [int(i) for i in input().split()]
b_books = [int(i) for i in input().split()]

#print(a_books)
data = ['a'] * n + ['b'] * m
all_lists = set()
for list in itertools.permutations(data):
  if list not in all_lists:
    all_lists.add(list)
#print(all_lists)
max_count = 0
for list in all_lists:
  count = 0
  a = 0
  b = 0
  time = 0
  for i in range(n+m):
    if list[i] == 'a':
      time += a_books[a]
      if time > k:
        break
      count += 1
      a += 1
    if list[i] == 'b':
      time += b_books[b]
      if time > k:
        break
      count += 1
      b += 1
  if count > max_count:
    max_count = count
  if max_count == n + m:
    break
print(max_count)

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    M, N, K = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))

    count = 0
    for m in range(M+1):
        sumA = sum(a[:m])
        if sumA > K:
            break
        for n in range(N+1):
            sumB = sum(b[:n])
            if sumB > K:
                break
            if (sumA + sumB) <= K:
                count = max(count, m + n)
            else:
                break
    print(count)

if __name__ == "__main__":
    resolve()

Submission status: Time Limit Exceeded

Solution code:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

sumA = [0]
sumB = [0]

for i in range(N):
    sumA.append(sumA[i] + A[i])

for i in range(M):
    sumB.append(sumB[i] + B[i])

maxValue = 0
for i in range(N+1):
    if sumA[i] > K:
        break
    for j in range(M+1):
        if sumA[i] + sumB[j] > K:
            break
        maxValue = max(maxValue, i+j)
print(maxValue)

Submission status: Time Limit Exceeded

Solution code:
#C
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
A = [0]
B = [0]
#読書時間A,B
for i in range(n):
    A.append(A[i] + a[i])
for i in range(m):
    B.append(B[i] + b[i])
ans = 0
#Aを増やしたときA+Bがkより小さくなるようなi,jを決めて最大値を決めてる
for i in range(n + 1):
    j = m
    if A[i] > k:
        break
    #K<=A[i]+B[j]となるまでjを引く>>k-A<=B
    while B[j] > k - A[i]:
        j -= 1
    ans = max(ans, i + j)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, m, k = map(int, input().split())

a_books = list(map(int, input().split()))
b_books = list(map(int, input().split()))

result = 0
for a in range(len(a_books) + 1):
    for b in range(len(b_books) + 1):
        a_time = sum(a_books[:a])
        b_time = sum(b_books[:b])
        count = a + b

        if k >= a_time + b_time and result < count:
            result = count

print(result)

Submission status: Time Limit Exceeded

Solution code:
n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

sum_A = [0 for _ in range(n+1)] # sum_A[i]:=上からi冊の本を読むときにかかる時間
for i in range(1, n+1):
    sum_A[i] = sum_A[i-1] + A[i-1]
sum_B = [0 for _ in range(m+1)] # sum_B[i]:=上からj冊の本を読むときにかかる時間
for j in range(1, m+1):
    sum_B[j] = sum_B[j-1] + B[j-1]

ans = 0
i = 0
while i <= n and sum_A[i] <= k:
    j = 0
    while j <= m and sum_A[i] + sum_B[j] <= k:
        j += 1
    ans = max(ans, i + j-1)
    i += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, m, k = map(int, input().split())

a_books = list(map(int, input().split()))
b_books = list(map(int, input().split()))


def read(books, remaining_time):
    read_books = []
    while remaining_time > 0:
        if books:
            time = books.pop(0)
            if remaining_time < time:
                break
            else:
                remaining_time -= time
                read_books.append(time)
        else:
            break
    return (read_books, remaining_time)


a_read_books, remaining_time = read(a_books, k)

a_not_read_time = 0
a_count = len(a_read_books)
b_count = 0

for a_reduce_count in range(len(a_read_books)):
    if a_reduce_count > 0:
        a_not_read_time += a_read_books[-a_reduce_count]

    b_read_books, _ = read(list(b_books), remaining_time + a_not_read_time)

    if len(b_read_books) > b_count:
        a_count = len(a_read_books) - a_reduce_count
        b_count = len(b_read_books)

print(a_count + b_count)

Submission status: Time Limit Exceeded

Solution code:
n, m, k = map(int, input().split())

a_books = list(map(int, input().split()))
b_books = list(map(int, input().split()))


def read(books, remaining_time):
    read_books = []
    while remaining_time > 0:
        if books:
            time = books.pop(0)
            if remaining_time < time:
                break
            else:
                remaining_time -= time
                read_books.append(time)
        else:
            break
    return (read_books, remaining_time)


a_read_books, remaining_time = read(a_books, k)

a_count = len(a_read_books)
b_count = 0

for a_reduce_count in range(len(a_read_books)):
    if a_reduce_count == 0:
        a_not_read_time = sum(a_books[:-1])
    else:
        a_not_read_time = sum(a_books[:-a_reduce_count])

    b_read_books, _ = read(b_books, remaining_time + a_not_read_time)

    if len(b_read_books) > b_count:
        a_count = len(a_read_books) - a_reduce_count
        b_count = len(b_read_books)

print(a_count + b_count)

Submission status: Time Limit Exceeded

Solution code:
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
time = 0
cnt = 0
C = []
SA =[0]
SB =[0]
for a in A:
    SA.append(SA[-1] + a)
for b in B:
    SB.append(SB[-1] + b)
for x in range(N+1):
    L = K - SA[x]
    if L < 0:
        break
    y_max = 0
    for y in range(M+1):
        T = SB[y]
        if L >= T:
            y_max += 1
        else:
            break
    C.append(y_max - 1 + x)
print(max(C))

Submission status: Time Limit Exceeded

Solution code:
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
time = 0
cnt = 0
C = []
for x in range(N+1):
    L = K - sum(A[0:x])
    if L < 0:
        break
    y_max = 0
    for y in range(M+1):
        T = sum(B[0:y])
        if L >= T:
            y_max += 1
        else:
            break
    C.append(y_max - 1 + x)
print(max(C))