Problem: 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.

Submission attempts (in order):






n, m, k = map(int, input().split())
arr1 = list(map(int, input().split()))
arr2 = list(map(int, input().split()))

acum1 = [0]
for i in range(n):
    acum1.append( arr1[-1] + arr1[i] )

acum2 = [0]
for i in range(m):
    acum2.append( arr2[-1] + arr2[i])

ans = 0
j = m
for i in range(n+1): 
    if acum1[i] < k:
        break
    while acum2[j] > k - acum1[i] and j>0: 

            j -= 1
    ans = max(0,i+j)

print(ans)

n,m,k = map(int, input().split())
arr1 = list(map(int,input().split()))
arr2 = list(map(int,input().split()))

acum1 = [0]
for i in range(n):
    acum1.append(acum1[-1]+arr1[i])

acum2 = [0]
for i in range(m):
    acum2.append(acum2[-1]+arr2[i])

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

print(ans)







n, m, k = map(int, input().split())
arr1 = list(map(int, input().split()))
arr2 = list(map(int, input().split()))

acum1 = [0]
for i in range(n):
    acum1.append( arr1[-1] + arr1[i] )

acum2 = [0]
for i in range(m):
    acum2.append( arr2[-1] + arr2[i])

ans = 0
j = m
for i in range(n+1): 
    if acum1[i] < k:
        break
    while acum2[j] > k - acum1[i] and j>0: 

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

print(ans)







n, m, k = map(int, input().split())
arr1 = list(map(int, input().split()))
arr2 = list(map(int, input().split()))

acum1 = [0]
for i in range(n):
    acum1.append( arr1[-1] + arr1[i] )

acum2 = [0]
for i in range(m):
    acum2.append( arr2[-1] + arr2[i])

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

print(ans)

from collections import deque

n,m,k = map(int,input().split(" "))

a = deque(list(map(int,input().split())))
b = deque(list(map(int,input().split())))
cnt = 0
total = 0

if a[0]==True and b[0]==True:
    while total+a[0] < k or total+b[0] < k:
        if len(a) > 0 and len(b) > 0:
            picked = min(a[0],b[0])
            if picked == a[0]:
                total += a.popleft()
                if len(a)==0 or len(b)==0:
                    break
                cnt += 1
            else:
                total += b.popleft()
                cnt += 1
elif a[0] and b[0]==False:
    while total + a[0] < k:
        total +=a.popleft()
        if len(a) == 0:
            break
        cnt += 1
else:
    while total + b[0] < k:
        total += b.popleft()
        if len(b) == 0:
            break
        cnt += 1
    
print(cnt)

from collections import deque

n,m,k = map(int,input().split(" "))

a = deque(list(map(int,input().split())))
b = deque(list(map(int,input().split())))
cnt = 0
total = 0

if a[0]==True and b[0]==True:
    while total+a[0] < k or total+b[0] < k:
        if len(a) > 0 and len(b) > 0:
            picked = min(a[0],b[0])
            if picked == a[0]:
                total += a.popleft()
                cnt += 1
                print(total,cnt)
                if len(a)==0: 
                    break
            else:
                total += b.popleft()
                cnt += 1
                print(total,cnt)
                if len(b)==0:
                    break
elif a[0] and b[0]==False:
    while total + a[0] < k:
        total +=a.popleft()
        cnt += 1
        if len(a) == 0:
            break
else:
    while total + b[0] < k:
        total += b.popleft()
        cnt += 1
        if len(b)==0:
            break
    
print(cnt)







n, m, k = map(int, input().split())
arr1 = list(map(int, input().split()))
arr2 = list(map(int, input().split()))

acum1 = [0]
for i in range(n):
    acum1.append( arr1[-1] + arr1[i] )

acum2 = [0]
for i in range(m):
    acum2.append( arr2[-1] + arr2[i])

ans = 0
j = m
for i in range(n):
    if acum1[i] < k:
        break
    while acum1[i] + acum2[j] > k and acum2[j]>0: 

            j -= 1
    ans = max(0,i+j)

print(ans)

n,m,k = map(int,input().split())
arr1 = list(map(int,input().split()))
arr2 = list(map(int,input().split()))

acum1 = [0]
for i in range(n):
    acum1.append( acum1[-1] + arr1[i])

acum2 = [0]
for i in range(m):
    acum2.append(acum2[-1] + arr2[i])

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

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Accepted