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()))

A_cumsum, B_cumsum = [0], [0]

for i in range(n):
    A_cumsum.append(A_cumsum[i] + A[i])
    
for j in range(m):
    B_cumsum.append(B_cumsum[j] + B[j])
    
ans = 0

for i, a in enumerate(A_cumsum):
    if a > k:
        break
    
    for j, b in enumerate(B_cumsum):
        if a + b > k:
            break
        elif (i + j) > ans:
                ans = (i + j)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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)

A = np.array(A)
B = np.array(B)

A_cumsum = np.cumsum(A)
B_cumsum = np.cumsum(B)

ans = 0

for i, a in enumerate(A_cumsum):
    for j, b in enumerate(B_cumsum):
        n = i + j
        if n > ans:
            if a + b <= k:
                ans = n
            else:
                break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N,M,K = list(map(int,input().split()))
A = np.array(list(map(int,input().split())))
B = np.array(list(map(int,input().split())))

sum_A = sum(A)
sum_B = sum(B)
if sum_A > K: # 時間を超過する場合
    tmp_cnt = 0
    for i,a in enumerate(A):
        tmp_cnt += a
        if tmp_cnt > K:
            break
    A_n_max = i
else: #時間を超過しない場合
    A_n_max = len(A)
    
cnt = 0
best_cnt = 0
b_start=0
for a_sub_i in range(A_n_max):
    cnt = A_n_max - a_sub_i
    time_left = K - A[:(A_n_max - a_sub_i)].sum()
   # print(a_sub_i)
   # print(time_left)
    for b_j in range(b_start, len(B)):
      #  print(b_j)
        if (time_left - B[:(b_j+1)].sum()) < 0:
            cnt = cnt + b_j
    #        print(f"b done {b_j}")
            break
        if b_j == (len(B)-1):
            cnt = cnt + b_j +1
     #       print(f"b done__ {b_j}")
            break
    b_start = b_j        
    if cnt > best_cnt:
        best_cnt = cnt
        
print(best_cnt)

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()))

sum_A = sum(A)
sum_B = sum(B)
if sum_A > K: # 時間を超過する場合
    tmp_cnt = 0
    for i,a in enumerate(A):
        tmp_cnt += a
        if tmp_cnt > K:
            break
    A_n_max = i
else: #時間を超過しない場合
    A_n_max = len(A)
    
cnt = 0
best_cnt = 0
b_start=0
for a_sub_i in range(A_n_max):
    cnt = A_n_max - a_sub_i
    time_left = K - sum(A[:(A_n_max - a_sub_i)])
   # print(a_sub_i)
   # print(time_left)
    for b_j in range(b_start, len(B)):
      #  print(b_j)
        if (time_left - sum(B[:(b_j+1)])) < 0:
            cnt = cnt + b_j
    #        print(f"b done {b_j}")
            break
        if b_j == (len(B)-1):
            cnt = cnt + b_j +1
     #       print(f"b done__ {b_j}")
            break
    b_start = b_j        
    if cnt > best_cnt:
        best_cnt = cnt
        
print(best_cnt)

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()))

sum_A = sum(A)
sum_B = sum(B)
if sum_A > K: # 時間を超過する場合
    tmp_cnt = 0
    for i,a in enumerate(A):
        tmp_cnt += a
        if tmp_cnt > K:
            break
    A_n_max = i
else: #時間を超過しない場合
    A_n_max = len(A)
    
cnt = 0
best_cnt = 0
for a_sub_i in range(A_n_max):
    cnt = A_n_max - a_sub_i
    time_left = K - sum(A[:(A_n_max - a_sub_i)])
   # print(a_sub_i)
   # print(time_left)
    for b_j in range(len(B)):
      #  print(b_j)
        if (time_left - sum(B[:(b_j+1)])) < 0:
            cnt = cnt + b_j
    #        print(f"b done {b_j}")
            break
        if b_j == (len(B)-1):
            cnt = cnt + b_j +1
     #       print(f"b done__ {b_j}")
            break
            
    if cnt > best_cnt:
        best_cnt = cnt
        
print(best_cnt)

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
max_num = 0
j = 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 a[i] > K:
        break
    else:
        j = M
        while b[j] > K - a[i]:
            j -=1
            if j <0:
                break
    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()))
a = [0]
b = [0]
ans = 0
max_num = 0
j = 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 a[i] > K:
        break
    else:
        j = M
        while b[j] > K - a[i]:
            j -=1
            if j <0:
                break
        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()))
a = [0]
b = [0]
ans = 0
max_num = 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):
    j = M
    if a[i] > K:
        break
    else:
        while b[j] > K - a[i]:
            j -=1
            if j <0:
                break
        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()))
a = [0]
b = [0]
ans = 0
max_num = 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):
    j = M
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j -=1
        if j <0:
            break
    ans = max(ans,i + j)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, M, K =  map(int, input().split())
stack1 = list(map(int, input().split()))
stack2 = list(map(int, input().split()))
i, count, total = 0, 0, 0
while total < K:
    if len(stack1) != 0 and len(stack2) != 0:
        if stack1[i] > stack2[i]:
            
            if total + stack2[i] <= K:
                total += stack2[i]
                stack2.pop(i)
                count += 1
            else:
                continue
        elif stack1[i] < stack2[i]:

            total += stack1[i]
            count += 1  
            stack1.pop(i)
            if total > K:
                count -= 1
                break
    elif len(stack1) == 0 and len(stack2) != 0:
        total += stack2[i]
        stack2.pop(i)
        count += 1
        if total > K:
            count -= 1
            break
    elif len(stack2) == 0 and len(stack1) != 0:
        total += stack1[i]
        stack1.pop(i)
        count += 1
        if total > K:
            count -= 1
            break
    else:
        break
    
print(count)

Submission status: Time Limit Exceeded

Solution code:
def abc172c_tsundoku():
    n, m, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    A = [0] * (n + 1)
    B = [0] * (m + 1)

    for i in range(1, n + 1):
        A[i] = A[i - 1] + a[i - 1]
        if A[i] > k:
            n = i - 1
            break
    for i in range(1, m + 1):
        B[i] = B[i - 1] + b[i - 1]
        if B[i] > k:
            m = i - 1
            break
    ans = 0
    for i in range(0, n+1):
        j = 0
        for j in range(0, m+1):
            if A[i] + B[j] > k:
                j -= 1
                break
        ans = max(i + j, ans)
    print(ans)


abc172c_tsundoku()

Submission status: Time Limit Exceeded

Solution code:
def abc172c_tsundoku():
    n, m, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    A = [0] * (n+1)
    B = [0] * (m+1)

    for i in range(1, n+1):
        A[i] = A[i - 1] + a[i - 1]
    for i in range(1, m+1):
        B[i] = B[i - 1] + b[i - 1]
    ans = 0
    for i in range(0, n+1):
        if A[i] > k: break
        j = 0
        for j in range(0, m+1):
            if A[i] + B[j] > k:
                j -= 1
                break
        ans = max(i + j, ans)
    print(ans)

abc172c_tsundoku()

Submission status: Time Limit Exceeded

Solution code:
n, m, k = map(int, input().split())
aa = list(map(int, input().split()))
bb = list(map(int, input().split()))
ans = [0]
time_sum = 0
i, j = 0, 0

flag_a = True
flag_b = True
flag = False
for i in range(0, len(aa)+1):
    for j in range(0, len(bb)+1):
        asum, bsum = sum(aa[:i]), sum(bb[:j])
        if k < asum and k < bsum:
            flag = True
            break
        else:
            time_total = asum + bsum
            if time_total > k:
                break
            else:
                ans.append(i+j)
    if flag:
        break

print(max(ans))

Submission status: Time Limit Exceeded

Solution code:
n, m, k = map(int, input().split())
aa = list(map(int, input().split()))
bb = list(map(int, input().split()))
ans = [0]
time_sum = 0
i, j = 0, 0

flag_a = True
flag_b = True
flag = False
for i in range(0, len(aa)+1):
    for j in range(0, len(bb)+1):
        asum, bsum = sum(aa[:i]), sum(bb[:j])
        if k < asum or k < bsum:
            flag = False
            break
        else:
            time_total = asum + bsum
            if time_total > k:
                break
            else:
                ans.append(i+j)
    if flag:
        break

print(max(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()))

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

ans = 0 
for a, asum in enumerate(Asum):
  if asum > K:
    break
  b=M
  while Bsum[b]>K - asum:
    b-=1
  ans = max(ans, a+b)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
A, B, LIMIT = map(int, input().split())
A=list(map(int, input().split()))
B=list(map(int, input().split()))

t=0
newA=[]
for a in A:
  t += a
  newA.append(a)
  if t>LIMIT:
    newA.pop()
    break
    
newA=sorted(newA)
newAsum=[0]
for i, v in enumerate(newA):
  newAsum.append(newAsum[i]+v)

cnt=0
for i, a in enumerate(newAsum):
  j=0
  cnt2=i
  t = a
  for b in B:
    t += b
    if t>LIMIT:
      break
    cnt2+=1
  cnt = max(cnt, cnt2)
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
A, B, time = input().split(" ")

a = input().split(" ")
Desk_A = a[:int(A)]
b = input().split(" ")
Desk_B = b[:int(B)]

count = 0
time_f = 0
FLAG = True
FLAG2 = True


while time_f < int(time):
    if 0 < len(Desk_A) and time_f + int(Desk_A[0]) <= int(time):
        time_f = time_f + int(Desk_A[0])
        Desk_A.remove(Desk_A[0])
        count += 1
    else:
        FLAG = False
    if 0 < len(Desk_B) and time_f + int(Desk_B[0]) <= int(time):
        time_f = time_f + int(Desk_B[0])
        Desk_B.remove(Desk_B[0])
        count += 1
    else:
        FLAG2 = False

    if FLAG is False and FLAG2 is False:
        break
    
print(count)

Submission status: Time Limit Exceeded

Solution code:
A, B, time = input().split(" ")

a = input().split(" ")
Desk_A = a[:int(A)]
b = input().split(" ")
Desk_B = b[:int(B)]

count = 0
time_f = 0
FLAG = True
FLAG2 = True
i = 0

while time_f < int(time):
    if i < len(Desk_A) and time_f + int(Desk_A[i]) <= int(time):
        time_f = time_f + int(Desk_A[i])
        Desk_A.remove(Desk_A[i])
        count += 1
    else:
        FLAG = False
        if time_f >= int(time):
            break

    if i < len(Desk_B) and time_f + int(Desk_B[i]) <= int(time):
        time_f = time_f + int(Desk_B[i])
        Desk_B.remove(Desk_B[i])
        count += 1

    else:
        FLAG2 = False
        if time_f >= int(time):
            break

    if FLAG is False and FLAG2 is False:
        break


print(count)

Submission status: Time Limit Exceeded

Solution code:
n, m, k = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]

t = 0
ans = 0

for i in range(n):
  t = sum(a[:i+1])
  if t <= k and i + 1 > ans:
      ans = i + 1
  elif t > k:
    break

  for j in range(m):
    t = sum(a[:i+1]) + sum(b[:j+1])
    if t <= k and i + j + 2> ans:
      ans = i + j + 2
    elif t > k:
      break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, m, k = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]

t = 0
ans = 0

for i in range(n):
  if sum(a[:i+1]) <= k and i + 1 > ans:
      ans = i + 1

  for j in range(m):
    if sum(a[:i+1]) + sum(b[:j+1]) <= k and i + j + 2> ans:
      ans = i + j + 2

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()))

time, count_all, count_a, count_b = 0, 0, 0, 0

while(time < K):
    if(count_all == 0 and len(A) <= len(B)):
        if(B[0] > K):
            break

    elif(count_all == 0 and len(A) >= len(B)):
        if(A[0] > K):
            break

    if(len(A) <= len(B)):
        time = time + B[count_b]
        B.pop(0)
        count_all = count_all + 1

    else:
        time = time + A[count_a]
        A.pop(0)
        count_all = count_all + 1

print(count_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()))

nmax = 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])

ans = 0

for i in range(N + 1):
    if a[i] > K:
        break

    for j in range(M+1):
        if b[j] + a[i] > K:
            break
        ans = max(ans, i+j)

print(ans)
exit()

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()))

nmax = 0

for na in range(N-1, -2, -1):
    for nb in range(M-1, -2, -1):
        n = na + nb + 2
        if n < nmax:
            continue
        time = sum([A[i] for i in range(na+1)]) + \
            sum([B[i] for i in range(nb+1)])
        if time <= K:
            nmax = n

print(nmax)
exit()

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations_with_replacement, product, permutations, combinations

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

nmax = 0

for na in range(-1, N):
    for nb in range(-1, M):
        n = na + nb + 2
        time = sum([A[i] for i in range(na+1)]) + \
            sum([B[i] for i in range(nb+1)])
        if nmax < n and time <= K:
            nmax = n

print(nmax)
exit()

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]
for i in range(N):
  sumA.append(sumA[-1]+A[i])
sumB=[0]
for i in range(M):
  sumB.append(sumB[-1]+B[i])

ans=0
for i in range(N+1):
  k=K-sumA[i]
  if k<0:
    break
  l=len([x for x in sumB if x<=k])-1
  ans=max(ans,i+l)
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()))
la = [0]
lb = [0]
mx = 0
for i in range(n): 
    if la[i] + a[i] > k:
        break
    la.append(la[i]+a[i])
for j in range(m):
    if lb[j] + b[j] > k:
        break
    lb.append(lb[j]+b[j])
for l in range(len(la)):
    cnt = l
    q = 0
    p = 0
    while la[l] + p <= k:
        q += 1
        if q == len(lb):
            cnt += len(lb)-1
            break
        p = lb[q] 
    if cnt == l:
        cnt += q - 1
    if cnt > mx:
        mx = cnt
print(mx)

Submission status: Time Limit Exceeded

Solution code:
n,m,k = map(int, input().split())
a_list = [int(x.strip()) for x in input().split()]
b_list = [int(y.strip()) for y in input().split()]
a_top,b_top,ans = 0,0,0
for i in range(n+1):
  if sum(a_list[:i]) > k:
    break
  else:
    for j in range(m+1):
      if sum(a_list[:i])+sum(b_list[:j]) > k:
        continue
      else:
        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()))

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 a_cnt in range(N + 1):
    if A[a_cnt] > K:
        continue
    b_cnt = M
    while A[a_cnt] + B[b_cnt] > K:
        b_cnt -= 1
    ans = max(ans, a_cnt + b_cnt)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import product

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

amax = 0
count = 0

for i in alst:
    if alst[amax] + count <= k:
        count += alst[amax]
        amax += 1
    else:
        break
# print("a:" + str(amax))
"""
while alst[amax] + count <= k:
    # print(str(amax) + " " + str(count))
    count += alst[amax]
    amax += 1
# print(amax)
#amaxはaの最大冊数
"""

anslst = []
count = 0
for i in range(amax+1):
    count = sum(alst[:i])
    bmax = 0
    for j in blst:
        if blst[bmax] + count <= k:
            count += blst[bmax]
            bmax += 1
        else:
            break
    # print("i:" + str(i) + " b:" + str(bmax))
    anslst.append(i+bmax)

print(max(anslst))

Submission status: Time Limit Exceeded

Solution code:
info = list(map(int, input().split()))
N = info[0]
M = info[1]
K = info[2]
L = max(N, M)

A_books = list(map(int, input().split()))
B_books = list(map(int, input().split()))


A_SUM = [0]
B_SUM = [0]
max_count = [0]

i = 0
while i < N:
    A_SUM.append(A_books[i] + A_SUM[i])
    i += 1
j = 0
while j < M:
    B_SUM.append(B_books[j] + B_SUM[j])
    j += 1

for k in range(N+1):
    for l in range(M+1):
        if (A_SUM[k] + B_SUM[l]) <= K:
            max_count.append(k + l)


print(max(max_count))

Submission status: Time Limit Exceeded

Solution code:
def getIntList(strList):
  return list(map(lambda x: int(x), strList))

N, M, K = getIntList(input().split(" "))
A = getIntList(input().split(" "))
B = getIntList(input().split(" "))

ta = 0
tb = 0
TA = [0]
TB = [0]

for i in range(len(A)):
  ta += A[i]
  if ta <= K:
    TA.append(ta)
  else:
    break
for j in range(len(B)):
  tb += B[j]
  if tb <= K:
    TB.append(tb)
  else:
    break

cnt = []

for i in range(len(TA)):
  for j in range(len(TB)):
#    print(" ".join([str(TA[i]), str(TB[-j-1]), str(K)]))
    if TA[i] + TB[-j-1] <= K:
      cnt.append(i - j + len(TB) - 1)
#      print(" ".join([str(i), str(j), str(len(TB)), "-1"]))
      break

print(max(cnt))

Submission status: Time Limit Exceeded

Solution code:
def getIntList(strList):
  return list(map(lambda x: int(x), strList))

N, M, K = getIntList(input().split(" "))
A = getIntList(input().split(" "))
B = getIntList(input().split(" "))

TA = 0
T = [0]
cnt = [] # idx = n of B books

for i in range(len(A)):
  TA += A[i]
  if TA <= K:
    T.append(TA)
  else:
    break

cnt.append(len(T) - 1)

for j in range(len(B)):
  T = list(filter(lambda t: t<= K, list(map(lambda t: t + B[j], T))))
  cnt.append(len(T) - 1)
  if len(T) <= 0:
    break

for k in range(len(cnt)):
  cnt[k] += k

print(max(cnt))

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()))
a_time = 0
b_time = 0
a_times = [0 for _ in range(N+1)]
b_times = [0 for _ in range(M+1)]
for i, a in enumerate(a_books):
  a_time += a
  a_times[i+1] = a_time
  
for i, b in enumerate(b_books):
  b_time += b
  b_times[i+1] = b_time
  
result = 0
l = 0
for i in range(N+1):
  if l == M:
    break
  for j in range(l, M+1):
    if a_times[N-i] + b_times[j] <= K:
      result = max(result, N-i+j)
    else:
      l = j
      break
print(result)

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()))
a_time = 0
b_time = 0
a_times = [0 for _ in range(N+1)]
b_times = [0 for _ in range(M+1)]
for i, a in enumerate(a_books):
  a_time += a
  a_times[i+1] = a_time
  
for i, b in enumerate(b_books):
  b_time += b
  b_times[i+1] = b_time
  
result = 0
l = 0
for i in range(N+1):
  for j in range(l, M+1):
    if a_times[N-i] + b_times[j] <= K:
      result = max(result, N-i+j)
    else:
      l = j
      break
print(result)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n,m,k = list(map(int, input().split()))
a_list = np.array(input().split()).astype(int)
b_list = np.array(input().split()).astype(int)
ans_list=[]
for i in range(n+1):
    for l in range(m+1):
        if sum(a_list[:i]) + sum(b_list[:l]) <= k:
            ans_list.append(i+l)
            

print(max(ans_list))

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]
for i in range(n):
  a.append(a[i]+A[i])
for j in range(m):
  b.append(b[j]+B[j])
#print(a,b)

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

Submission status: Time Limit Exceeded

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

n = int(n)
m = int(m)
k = int(k)
a = list(map(int, a))
b = list(map(int, b))

ans = 0
temp_a = {}
temp_b = {}

for i_a in range(n+1):
  if sum(a[0:i_a]) > k:
    break
  temp_a[i_a] = sum(a[0:i_a])
for i_b in range(m+1):
  if sum(b[0:i_b]) > k:
    break
  temp_b[i_b] = sum(b[0:i_b])
  
temp_a = sorted(temp_a.items(), key=lambda x:x[1], reverse=True)
temp_b = sorted(temp_b.items(), key=lambda x:x[1], reverse=True)
ans = {}

if len(temp_a) > len(temp_b):
  temp_a, temp_b = temp_b, temp_a
  n, m = m, n

for item_a in temp_a:
  for item_b in temp_b:
    if item_a[1] + item_b[1] > k:
      continue
    else:
      ans[len(ans)] = item_a[0] + item_b[0]
      break

ans = max(ans.values())
print(ans)

Submission status: Time Limit Exceeded

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

n = int(n)
m = int(m)
k = int(k)
a = list(map(int, a))
b = list(map(int, b))

ans = 0
temp_a = {}
temp_b = {}

for i_a in range(n+1):
  if sum(a[0:i_a]) > k:
    break
  temp_a[i_a] = sum(a[0:i_a])
for i_b in range(m+1):
  if sum(b[0:i_b]) > k:
    break
  temp_b[i_b] = sum(b[0:i_b])
  
temp_a = sorted(temp_a.items(), key=lambda x:x[1], reverse=True)
temp_b = sorted(temp_b.items(), key=lambda x:x[1], reverse=True)
ans = {}

for item_a in temp_a:
  for item_b in temp_b:
    if item_a[1] + item_b[1] > k:
      continue
    else:
      ans[len(ans)] = item_a[0] + item_b[0]
      break

ans = max(ans.values())
print(ans)

Submission status: Time Limit Exceeded

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

n = int(n)
m = int(m)
k = int(k)
a = list(map(int, a))
b = list(map(int, b))

ans = 0
temp_a = {}
temp_b = {}

for i_a in range(n+1):
  temp_a[i_a] = sum(a[0:i_a])
for i_b in range(m+1):
  temp_b[i_b] = sum(b[0:i_b])
  
temp_a = sorted(temp_a.items(), key=lambda x:x[1], reverse=True)
temp_b = sorted(temp_b.items(), key=lambda x:x[1], reverse=True)
ans = {}

for item_a in temp_a:
  for item_b in temp_b:
    if item_a[1] + item_b[1] > k:
      continue
    else:
      ans[len(ans)] = item_a[0] + item_b[0]
      break

ans = max(ans.values())
print(ans)

Submission status: Time Limit Exceeded

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

n = int(n)
m = int(m)
k = int(k)
a = list(map(int, a))
b = list(map(int, b))

ans = 0

for i_a in range(n+1):
  if sum(a[0:i_a])>k:
    break
  for i_b in range(m+1):
    if sum(a[0:i_a]) + sum(b[0:i_b]) <= k:
      ans = max(ans, len(a[0:i_a]) + len(b[0:i_b]))
    else:
      continue

print(ans)

Submission status: Time Limit Exceeded

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

n = int(n)
m = int(m)
k = int(k)
a = list(map(int, a))
b = list(map(int, b))

ans = 0

for i_a in range(n+1):
  a[0:i_a]
  for i_b in range(m+1):
    if sum(a[0:i_a]) + sum(b[0:i_b]) <= k:
      ans = max(ans, len(a[0:i_a]) + len(b[0:i_b]))

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
A=sorted(A)
B=list(map(int,input().split()))
B=sorted(B)
sum=0
while K>0:
    if len(A)==0:
        while K>=B[0]:
            sum += 1
            K=K-B[0]
            del B[0]
            if len(A)==0:
                break
    elif len(B)==0:
        while K>=A[0]:
            sum += 1
            K=K-A[0]
            del A[0]
            if len(B)==0:
                break
    elif A[0]<B[0]:
        if K>=A[0]:
            sum += 1
            K=K-A[0]
            del A[0]
    else:
        if K>=B[0]:
            sum += 1
            K=K-B[0]
            del B[0]
        else:
            break
print(sum)

Submission status: Time Limit Exceeded

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

def check_(lis, num, ti):
    ans = 0
    for i in range(num+1):
        if ans >= ti:
            break
        ans +=  lis[i]
    return i

max_a = check_(a, m, k)
max_b = check_(b, n, k)
ans = 0
for i in range(max_a+1):
    for j in range(max_b+1):
        if sum(a[:i+1]) + sum(b[:j+1]) <= k and i + j > ans:
            ans = i+j 
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

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

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

INF = float('inf')
# dp[n][m] represents total time took to read top n book from A and top m book from B
dp = [[INF] * (M+1) for _ in range(N+1)]
dp[0][0] = 0

count = 0
for i in range(N):
    dp[i+1][0] = dp[i][0] + A[i]
    if dp[i+1][0] > K:
        break
    else:
        count = max(count, i+1)

for i in range(N+1):
    for j in range(M):
        dp[i][j+1] = dp[i][j] + B[j]
        if dp[i][j+1] > K:
            break
        else:
            count = max(i + j + 1, count)

print(count)

Submission status: Time Limit Exceeded

Solution code:
def cul(lists):
    culist = []
    lene = len(lists)
    culist = [sum(lists[0:x:1]) for x in range(0, lene + 1)]
    return culist[1:]


n, m, k = map(int, input().split())
a = list(map(int, input().split()))[:n]
b = list(map(int, input().split()))[:m]
all = 0
all2 = 0
g = 0
z = 0
a = cul(a)
b = cul(b)
for i in range(n):
    if a[i] <= k:
        g += 1
    else:
        break

all += a[i - 1]

for i in range(m):
    if all + b[i] <= k:
        g += 1
    else:
        break

for i in range(m):
    if b[i] <= k:
        z += 1
    else:
        break

all2 += b[i - 1]
for i in range(n):
    if all2 + a[i] <= k:
        z += 1
    else:
        break

print(max(g, z))

Submission status: Time Limit Exceeded

Solution code:
def cul(lists):
    culist = []
    lene = len(lists)
    culist = [sum(lists[0:x:1]) for x in range(0, lene + 1)]
    return culist[1:]


n, m, k = map(int, input().split())
li = list(map(int, input().split()))[:n]
li2 = list(map(int, input().split()))[:m]
all = 0
all2 = 0
g = 0
z = 0
a = cul(li)
b = cul(li2)
for i in range(n):
    if a[i] <= k:
        g += 1
    else:
        break

all += a[i-1]

for i in range(m):
    if all + b[i] <= k:
        g += 1
    else:
        break

for i in range(m):
    if b[i] <= k:
        z += 1
    else:
        break

all2 += b[i-1]
for i in range(n):
    if all2 + a[i] <= k:
        z += 1
    else:
        break

print(max(g, z))

Submission status: Time Limit Exceeded

Solution code:
import bisect
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):
  if A[i]+a[i] <=K:
    A.append(A[i]+a[i])
  else:
    break

for i in range(M):
  if B[i]+b[i] <=K:
    B.append(B[i]+b[i])
  else:
    break

if len(A)==1 and len(B)==1:
  print(0)
  exit()
for i in range(len(A)):
  for j in range(len(B)):
    if A[i]+B[j]<=K:
      ans = max(ans,i+j)
    else:
      break
      
print(ans)