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: Runtime Error

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


f = open('b20.txt')
data = f.readlines()
data = [d.replace("\n", "").split(" ") for d in data]
N, M, K = map(int, data[0])
A_list = list(map(int, data[1]))
B_list = list(map(int, data[2]))

A_list.insert(0, 0)
B_list.insert(0, 0)
B_cumsum = np.cumsum(B_list)

time = B_cumsum[-1]
ans, j = 0, M

B_list[j]
for i in range(N+1):
    if (time > K):
        break
    while (j > 0 and time > K):
        time -= B_list[j]
        j -= 1
    
    ans = max(ans, i+j)
    time += A_list[i]

print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from collections import deque
n,m,k = map(int,input().split())
la = list(map(int,input().split()))
lb = list(map(int,input().split()))
la = deque(la)
lb = deque(lb)
inf = float("inf")
dp = [[-inf]*(k+1) for _ in range(n+m+1)]
for j in range(k+1):
    dp[0][j] = 0
for i in range(n+m):
    if la != deque([]) and lb != deque([]):
        if la[0] <= lb[0]:
            s = la.popleft()
        else:
            s = lb.popleft()
    elif la != deque([]) and lb == deque([]):
        s = la.popleft()
    elif la == deque([]) and lb != deque([]):
        s = lb.popleft()
    elif la == deque([]) and lb == deque([]):
        break
    for l in range(k+1):
        if l-s >=0:
            dp[i+1][l] = max(dp[i][l],dp[i][l-s]+1)
        else:
            dp[i+1][l] = dp[i][l]
a = 0
for p in range(n+m+1):
    if a < max(dp[p]):
        a = max(dp[p])
print(a)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

while K - sum(time) >= 0:
    if sum(A) == 0:
        if sum(B) == 0:
            break
        if K - sum(time) >= min(B):
            #print('B:', B)
            time.append(min(B))
            B.pop()
            count += 1
            #print('K - sum(time)b:', K - sum(time))
            print('最終結果：A', A, '最終結果：B', B, '残時間：', K - sum(time))
            continue


    elif sum(B) == 0:
        if sum(A) == 0:
            break
        if K - sum(time) >= min(A):
            #print('A:', A)
            time.append(min(A))
            A.pop()
            count += 1
            #print('K - sum(time)a:', K - sum(time))
            print('最終結果：A', A, '最終結果：B', B, '残時間：', K - sum(time))
            continue


    if min(A) >= min(B):
        if K - sum(time) >= min(B):
            #print('B:', B)
            time.append(min(B))
            B.pop()
            count += 1
            #print('K - sum(time)b:', K - sum(time))
            print('最終結果：A', A, '最終結果：B', B, '残時間：', K - sum(time))
            continue
        else:
            break
    else:
        if K - sum(time) >= min(A):
            #print('A:', A)
            time.append(min(A))
            A.pop()
            count += 1
            #print('K - sum(time)a:', K - sum(time))
            print('最終結果：A', A, '最終結果：B', B, '残時間：', K - sum(time))
            continue
        else:
            break

print(count)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
a, b = iter(A), iter(B)
now_a, now_b = next(a), next(b)
ans, cnt_time = 0, 0
ex_a = True
ex_b = True
this_time_cnt_time = 0

while cnt_time < K:
    #print('\n------',cnt_time)
    this_time_cnt_time = cnt_time
    if now_a > now_b and ex_b:
        try:
            ans += 1
            cnt_time += now_b
            #print('b', now_b, cnt_time, ans)
            now_b = next(b)
        except StopIteration:
            #print('b--')
            ex_b = False
            continue
    elif now_a <= now_b and ex_a:
        try:
            ans += 1
            cnt_time += now_a
            #print('a', now_a, cnt_time, ans)
            now_a = next(a)
        except StopIteration:
            #print('a--')        
            ex_a = False
            continue
    elif ex_b:
        try:
            ans += 1
            cnt_time += now_b
            #print('b2', now_b, cnt_time, ans)
            now_b = next(b)
        except StopIteration:
            #print('b2--')
            ex_b = False
            continue
    elif ex_a:
        try:
            ans += 1
            cnt_time += now_a
            #print('a2', now_a, cnt_time, ans)
            now_a = next(a)
        except StopIteration:
            #print('a2--')
            ex_a = False
            continue
    if this_time_cnt_time == cnt_time:
        ans+=1
        #print('aaaaaaa')
        break
if not ex_a and not ex_b:
    #print('***', ans, ex_a, ex_b)
    ans+=1
print(ans-1)

Submission status: Runtime Error

Solution code:
from itertools import accumulate

N, M, K = map(int, input().split())
a = list(accumulate(int(i) for i in input().split(), initial=0))
b = list(accumulate(int(i) for i in input().split(), initial=0))

cnt = 0
best0 = M
for i in range(N+1):
    ai = a[i]
    for j in range(best0, -1, -1):
        bj = b[j]
        if ai + bj <= K:
            cnt = max(cnt, i + j)
            best0 = j
            break

print(cnt)

Submission status: Runtime Error

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

    maxv = 0
    acum = [0] * (n + 1)
    bcum = [0] * (m + 1)
    for i in range(n):
        acum[i + 1] = acum[i] + a[i]
    for i in range(m):
        bcum[i + 1] = bcum[i] + b[i]

    for i in range(n + 1):
        if acum[i] > k:
            continue
        maxv = max(maxv, i + bisect_right(bcum, k - acum[i]) - 1)
    print(maxv)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
for i in range(1,n):
    a[i] += a[i-1]
for i in range(1,m):
    b[i] += b[i-1]
a = [0]+a
b = [0]+b

ans = 0
ALL = 0
j = m
B = b[j-1]

for i in range(n+1):
    ALL = a[i]
    if ALL > k:
        continue
    else:
        while k-ALL <= B :
            B =b[j-1]
            j -=1

    ans = max(ans,i+j)
print(ans)

Submission status: Runtime Error

Solution code:
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
for i in range(1,n):
    a[i] += a[i-1]
for i in range(1,m):
    b[i] += b[i-1]
a = [0]+a
b = [0]+b

ans = 0
ALL = 0
from bisect import bisect
for i in range(n+1):
    ALL = a[i]
    if ALL > k:
        continue
    else:idx = bisect(b,k-ALL)
    #print(i,ALL,idx)
        ans = max(ans,i+idx-1)
print(ans)

Submission status: Runtime Error

Solution code:
from sys import stdin
data = stdin.readlines()

n = int(data[0].split()[0])
m = int(data[0].split()[1])

k = int(data[0].split()[2])

A = [int(s) for s in data[1].split()]
B = [int(s) for s in data[2].split()]

a = [0]
b = [0]

for i in range(n):
    a.append(a[i]+A[i])
for i in range(m):
    b.append(b[i]+B[i])
a.pop(0)
b.pop(0)

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

Submission status: Runtime Error

Solution code:
from sys import stdin
data = stdin.readlines()

n = int(data[0].split()[0])
m = int(data[0].split()[1])

k = int(data[0].split()[2])

A = [int(s) for s in data[1].split()]
B = [int(s) for s in data[2].split()]

a = [0]
b = [0]

for i in range(n):
    a.append(a[i]+A[i])
for i in range(m):
    b.append(b[i]+B[i])
a.pop(0)
b.pop(0)

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

Submission status: Runtime Error

Solution code:
import itertools,sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N,M,K = LI()
A = LI()
B = LI()
accumulate_A = list(itertools.accumulate(A))
accumulate_B = list(itertools.accumulate(B))
ans,j = 0,M-1
for i in range(N):
    if accumulate_A[i]>K:
        break
    while accumulate_A[i]+accumulate_B[j]>K:
        j -= 1
    ans = max(ans,i+j+2)
print(ans)

Submission status: Runtime Error

Solution code:
from sys import stdin
data = stdin.readlines()

n = int(data[0].split()[0])
m = int(data[0].split()[1])

k = int(data[0].split()[2])

A = [int(s) for s in data[1].split()]
B = [int(s) for s in data[2].split()]

a = [0]
b = [0]

for i in range(n):
    a.append(a[i]+A[i])
for i in range(m):
    b.append(b[i]+B[i])
a.pop(0)
b.pop(0)

ans = []
for i in range(n):
    if a[i] <= k:
        for j in reversed(range(m)):
            if a[i]+b[j] <= k:
                ans.append(i+j+2)
                break
print(max(ans))

Submission status: Runtime Error

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

cost = 0
res = 0
while cost < k:
  if a_lst[0] < b_lst[0]:
    if a_lst[0] + cost > k:
      break
    cost += a_lst.pop(0)
    res += 1
  else:
    if b_lst[0] + cost > k:
      break
    cost += b_lst.pop(0)
    res += 1    
print(res)

Submission status: Runtime Error

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

# A机から0〜N冊読んで、残り時間でB机から何冊読めるかを考える
lst = [0]*(N+1)

for i in range(N+1):
    time = 0
    time = sum(A[0:i])　# A机からi冊読んだときの所要時間
    if time > K:
        break # この時点で制限時間Kを超えていたらB机は無視する
    else:
        for j in range(M):
            # 
            if time + B[j] <= K:
                time = time + B[j]
            else:
                lst[i] = i + j
                break

res = max(lst)
print(res)

"""
3 4 240
60 90 120
80 150 80 150

3 4 730
60 90 120
80 150 80 150
"""

Submission status: Runtime Error

Solution code:
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)

Submission status: Runtime Error

Solution code:
from collections import deque
n,m,k=map(int, input().split())
a=deque(map(int, input().split()))
b=deque(map(int, input().split()))

count=0

while True:
    if (not a) and (not b):
        break
    elif ( (not a) and b) or a[0] > b[0]:
        if k < b[0]:
            break
        k-=b[0]
        count+=1
        b.popleft()
    else:
        if k < a[0]:
            break
        k-=a[0]
        count+=1
        a.popleft()


print(count)

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

Solution code:
import numpy as np

N,M,K = map(int,input().split())
A = np.array(input().split(),dtype=int)
B = np.array(input().split(),dtype=int)

AA = np.insert(A,0,0)
BB = np.insert(B,0,0)
AAA = np.cumsum(AA)
BBB = np.cumsum(BB)
max_mins = 0
max_books = 0
for a in enumerate(AAA):
    if a[1] > K:
        break
    for b in enumerate(BBB):
        if a[2] + b[1] > K:
            break
        if a[0] + b[0] > max_books:
            max_books = a[0] + b[0]
print(max_books)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
temp,temp2=0,0
Sa,Sb=[0]*n,[0]*m
for i in range(n):
    temp+=a[i]
    Sa[i]=temp
for i in range(m):
    temp2+=b[i]
    Sb[i]=temp2
ans,j=0,m-1
for i in range(n):
    if Sa[i]>k: break
    while Sa[i]+Sb[j]>k: j-=1
    ans=max(ans,i+j+2)
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
temp,temp2=0,0
Sa,Sb=[0]*n,[0]*m
for i in range(n):
    temp+=a[i]
    Sa[i]=temp
for i in range(m):
    temp2+=b[i]
    Sb[i]=temp2
temp=0
flag=0
ans=0
for i in range(n-1,-1,-1):
    S=Sa[i]
    if S+Sb[temp]>k: continue
    while S+Sb[temp]<=k:
        temp+=1
        if temp==m:
            flag=1
            break
    t=(i+1)+temp
    if t>ans: ans=t
    #if flag: break
print(ans)

Submission status: Runtime Error

Solution code:
import sys
readline = sys.stdin.readline

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

n = 0
m = 0
t = 0
for i in range(N):
  if t + A[i] <= K:
    n += 1
    t += A[i]
  else:
    break
for i in range(M):
  if t + B[i] <= K:
    m += 1
    t += B[i]
  else:
    break
max = n + m
for i in range(N):
  if n == 0 or m == M :
    break
  t -= A[n]
  n -= 1
  for j in range(M):
    if t + B[m + 1] <= K:
      m += 1
      t += B[m]
    else:
      break
    if m == M:
      break
  if n + m > max:
    max = n + m
print(max)

Submission status: Runtime Error

Solution code:
n,m,k = map(int,input().split())
ls_a = list(map(int,input().split()))
ls_b = list(map(int,input().split()))
 
n_max = n
for i in range(n):
  if sum(ls_a[:i+1]) > k:
    n_max = i
    break
    
readable_max = 0
pre_max = 0
for i in range(n_max, -1, -1):
  m_time = k - sum(ls_a[:i])
  
  m_max = m
  for j in range(pre_max, m+1):
    roop += 1
    
    if sum(ls_b[:j+1]) > m_time:
      m_max = j
      pre_max = j
      break
    elif j == m:
  	  break
  else:
    continue
  break
    
  if i + m_max > readable_max:
    readable_max = i + m_max
    
if i + m_max > readable_max:
    readable_max = i + m_max
    
print(readable_max)

Submission status: Runtime Error

Solution code:
import sys

n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ak=[]
aa=0
for i in a:
    aa+=i
    ak.append(aa)
bk=[]
bb=0
for i in b:
    bb+=i
    bk.append(bb)
ass=bs=0
for i in range(len(ak)):
    if ak[i]<=k:
        ass=i+1
    else:
        break
for i in range(len(bk)):
    if bk[i]+ak[ass-1]<=k:
        bs=i+1
    else:
        break
wk=ass+bs
aswk=ass
bswk=bs
if wk==n+m:
    print(n+m)
    sys.exit()

while aswk>1:
    aswk-=1
    while k< ak[aswk-1]+bk[bswk-1]:
        if bswk <=m:
            bswk+=1
        else:
            break
    if bs<=bswk-1:
        bs=bswk
        ass=aswk
    else:
        break        
print(ass+bs)

Submission status: Runtime Error

Solution code:
max_counter = 0

def check(limit, a, b, i, j, counter):
    global max_counter

    if len(a) > i:
        if limit - a[i] >= 0:

            check(limit - a[i], a, b, i + 1, j, counter + 1)

    if len(b) > j:
        if limit - b[j] >= 0:

            check(limit - b[j], a, b, i, j + 1, counter + 1)

    if counter > max_counter:
        max_counter = counter

    return

def main():
    global max_counter
    n, m, k = map(int, input().split())
    a = [int(x) for x in input().split()]
    b = [int(x) for x in input().split()]

    check(k, a, b, 0, 0, 0)

    print(max_counter)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import numpy

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

A_time = []
B_time = []

if sum(A) + sum(B) <= K:
    print(len(A) + len(B))
elif K < min(A) and K < min(B):
    print(0)
else:
    #A_res = list(numpy.cumsum(A))
    #B_res = list(numpy.cumsum(B))

    books = []

    for i in range(len(A)):
        A_sum = sum(A[0:i+1])
        if A_sum > K:
            break
        res = K - A_sum

        for j in range(M+1, 0, -1):
            B_sum = sum(B[0:j])
            if B_sum in B:
                books.append(i + j + 1)
                break
    print(max(books))

Submission status: Runtime Error

Solution code:
n=int(input())
l=[0 for i in range(n+1)]
for i in range(1,n+1):
 
    for j in range(i,n+1,i):
 
        l[j]+=1
c=0
for i in range(1,n+1):
    c+=i*l[i]
 
print(c)

Submission status: Runtime Error

Solution code:
n=int(input())
l=[0]*(n+1)
for i in range(1,n+1):

    for j in range(i,n+1,i):

        l[j]+=1
c=0
for i in range(1,n+1):
    c+=i*l[i]

print(c)

Submission status: Runtime Error

Solution code:
max_counter = 0

def check(limit, a, b, i, j, counter):
    global max_counter
    
    if len(a) > i:
        if limit - a[i] >= 0:

            check(limit - a[i], a, b, i + 1, j, counter + 1)

            if counter > max_counter:
                max_counter = counter

    if len(b) > j:
        if limit - b[j] >= 0:

            check(limit - b[j], a, b, i, j + 1, counter + 1)

            if counter > max_counter:
                max_counter = counter

    return

def main():
    global max_counter
    n, m, k = map(int, input().split())
    a = [int(x) for x in input().split()]
    b = [int(x) for x in input().split()]

    check(k, a, b, 0, 0, 1)

    print(max_counter)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import numpy
 
N,M,K = [int(i) for i in input().split()]
A= [int(i) for i in input().split()]
B= [int(i) for i in input().split()]
 
A_time = []
B_time = []
 
if sum(A) + sum(B) <= K:
    print(len(A) + len(B))
elif K < min(A) and K < min(B):
    print(0)
else:
    A_res = list(numpy.cumsum(A))
    B_res = list(numpy.cumsum(B))
 
    books = []
 
    for i in range(len(A_res)):
        if A[i] > K:
            break
        res = K - A[i]

        for b_best in range(int(res), 0, -1):
            if b_best in B_res:
                books.append(i + B_res.index(b_best) + 1)
                break
    print(max(books))

Submission status: Runtime Error

Solution code:
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)
X = 0
Y = 0
cnt = 0
for n in range(N):
    a[n+1] = a[n] + A[n]
for n in range(M):
    b[n+1] = b[n] + B[n]
for n in range(1, N+1):
    if a[n] <= K:
        X += 1
    else:
        break
for m in range(1, M+1):
    if b[m] <= K:
        Y += 1 
    else:
        break

if a[X] < b[Y]:
    K = K - a[X]
    cnt += X
    if K - b[Y] == 0:
        cnt += Y
    else:
        for y in range(1, Y):
            if b[y] <= K:
                cnt += 1
            else:
                break
else:
    K = K - b[Y]
    cnt += Y
    if K - b[X] == 0:
        cnt += X
    else:
        for x in range(1, X):
            if b[x] <= K:
                cnt += 1
            else:
                break
print(cnt)

Submission status: Runtime Error

Solution code:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split(​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, j = 0, M
for i in range(N + 1):
  if a[i] > K:
    break
  while b[j] > K - a[i]:
  	j -= 1
  ans = max(ans, i + j)
print(ans))))

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

Submission status: Runtime Error

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

    DP = [[0] * (M + 1) for _ in range(N + 1)]

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

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

    ans = 0
    for i in range(N + 1):
        MX = max(DP[i])
        if MX == 0: break
        j = DP[i].index(MX)
        ans = max(ans, i + j)

    print(ans)


if __name__ == '__main__':
    main()

exit()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))

import numpy as np

n,m,k = iim()
a = iil()
cuma = np.cumsum(a)
b = iil()
cumb = np.cumsum(b)

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

Submission status: Runtime Error

Solution code:
# f = open('test.txt')
f = open('b11.txt')
n, m, k = map(int, f.readline().split())
a = list(map(int, f.readline().split()))
b = list(map(int, f.readline().split()))

a_sum = [0]
b_sum = [0]
cnt = 0
best_b = m
confirm = ()

for i in a:
    a_sum.append(i + a_sum[-1])

for i in b:
    b_sum.append(i + b_sum[-1])

for a_idx in range(n + 1):
    if a_sum[a_idx] > k:
        break
    for b_idx in reversed(range(best_b + 1)):
        if b_sum[b_idx] + a_sum[a_idx] <= k:
            # if cnt < a_idx + b_idx:
            cnt = max(cnt, a_idx + b_idx)
            best_b = b_idx
            break

print(cnt)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
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)
X = 0
Y = 0
cnt = 0
for n in range(N):
    a[n+1] = a[n] + A[n]
for n in range(M):
    b[n+1] = b[n] + B[n]
for n in range(1, N+1):
    if a[n] <= K:
        X += 1
    else:
        break
for m in range(1, M+1):
    if b[m] <= K:
        Y += 1 
    else:
        break
if a[X] < b[Y]:
    K = K - a[X]
    cnt += X
    if K - b[Y] == 0:
        cnt += Y
    else:
        for y in range(1, Y):
            if b[y] < K:
                cnt += 1
            else:
                break
else:
    K = K - b[Y]
    cnt += Y
    if K - b[X] == 0:
        cnt += X
    else:
        for x in range(1, X):
            if b[x] < K:
                cnt += 1
            else:
                break
print(cnt)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N, M , K = map(int, input().split())
X = [0] + list(map(int, input().split()))
Y = list(map(int, input().split()))
R,sY,j= 0,sum(Y),M
for i in range(N):
    t += X[i]
    if t > K: break
    while j and sY+t > K:
        j-=1
        sY -= Y[j]
    R = max(R, j+i)
print(R)

Submission status: Runtime Error

Solution code:
N, M, K = map(int, input().split())
 
A = list(map(int, input().split()))
B = list(map(int, input().split()))
 
def solve(A, N, B, M, K):
  
  def cumsum(l):
    rt = [0]
    s = 0
    for n in l:
      s += n
      rt.append(s)
    return rt
  
  preA = cumsum(A)
  preB = cumsum(B)
  
  total = N + M
  s, e = 0, total
  
  def can_read(num):
    for i in range(N + 1):
      j = num - i
      if j < (M + 1) and (preA[i] + preB[j]) <= K:
      	return True
    return False

  res = 0
  while s <= e:
    mid = s + (e - s) // 2
    can = can_read(mid)
    
    if can:
      res = mid
      s = mid + 1
    else:
      e = mid - 1
  
  return res

res = solve(A, N, B, M, K)
print(res)

Submission status: Runtime Error

Solution code:
N, M, K = map(int, input().split())
 
A = list(map(int, input().split()))
B = list(map(int, input().split()))
 
def solve(A, N, B, M, K):
  
  def cumsum(l):
    rt = [0]
    s = 0
    for n in l:
      s += n
      rt.append(s)
    return rt
  
  preA = cumsum(A)
  preB = cumsum(B)
  
  total = N + M
  s, e = 0, total
  
  def can_read(num):
    for i in range(N + 1):
      j = num - i
      if j < (M + 1) and (preA[i] + preB[j]) <= K:
      	return True
    return False

  res = 0
  while s < e:
    mid = s + (e - s) // 2
    can = can_read(mid)
    
    if can:
      res = mid
      s = mid + 1
    else:
      e = mid - 1
  
  return res

res = solve(A, N, B, M, K)
print(res)

Submission status: Runtime Error

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

na, nb = [0], [0]
for i in range(n):
    na.append(na[i] + a[i])
for j in range(m):
    nb.append(nb[i] + b[i])

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

Submission status: Runtime Error

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

import numpy as np
import bisect

ra=list(np.cumsum(a))
rb=list(np.cumsum(b))

ans=0
j=m-1
for i in range(n):    
    capa = k - ra[i]
    if ra[i]>k:
        ans=max(ans,i)
        break
    while ra[i]+rb[j]>k:
        j-=1

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

Submission status: Runtime Error

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

na, nb = [0], [0]
for i in range(n):
    na.append(na[i] + a[i])
for j in range(m):
    nb.append(nb[i] + b[i])

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