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):
def c(x):
    if sb[x] + S <= k: return True
    else: return False


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

sa = []
sb = []

if a[0] <= k:
    sa.append(a[0])
    for i in range(1, n):
        if sa[i-1]+a[i] > k:
            break
        sa.append(sa[i-1]+a[i])

if b[0] <= k:
    sb.append(b[0])
    for j in range(1, m):
        if sb[j-1]+b[j] > k:
            break
        sb.append(sb[j-1]+b[j])

if len(sa) == 0:
    print(len(sb))
    exit()

for i in range(len(sa))[::-1]:
    mb = 0
    lb = len(sb)
    S = sa[i]
    if lb == 0 or S + sb[0] > k:
        print(len(sa))
        exit()
    
    while lb - mb > 1:
        mid = (mb+lb)//2
        if c(mid):
            mb = mid
        else:
            lb = mid
    ans = max(ans, i+1+lb)

print(ans)

def c(x):
    if sb[x] + S <= k: return True
    else: return False


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

sa = []
sb = []

if a[0] <= k:
    sa.append(a[0])
    for i in range(1, n):
        if sa[i-1]+a[i] > k:
            break
        sa.append(sa[i-1]+a[i])

if b[0] <= k:
    sb.append(b[0])
    for j in range(1, m):
        if sb[j-1]+b[j] > k:
            break
        sb.append(sb[j-1]+b[j])

if len(sa) == 0:
    print(len(sb))
    exit()

for i in range(len(sa))[::-1]:
    mb = 0
    lb = len(sb) - 1
    if len(sb) == 0 or sa[i] + sb[0] > k:
        print(len(sa))
        exit()
    
    while lb - mb > 1:
        mid = (mb+lb)//2
        if c(mid):
            mb = mid
        else:
            lb = mid
    ans = max(ans, i+1+lb)

print(ans)

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

sa = [0]
sb = [0]

for i in range(n):
    sa.append(sa[i]+a[i])

for i in range(m):
    sb.append(sb[i]+b[i])

ans = 0
j = m


for i in in range(n+1):
    if sa[i] > k:
        break
    while sa[i]+sb[j] > k:
        j -= 1
    ans = max(ans, i+j)

print(ans)

def c(x):
    if sb[x] + S <= k: return True
    else: return False


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

sa = []
sb = []

if a[0] <= k:
    sa.append(a[0])
    for i in range(1, n):
        if sa[i-1]+a[i] > k:
            break
        sa.append(sa[i-1]+a[i])

if b[0] <= k:
    sb.append(b[0])
    for j in range(1, m):
        if sb[j-1]+b[j] > k:
            break
        sb.append(sb[j-1]+b[j])

if len(sa) == 0:
    print(len(sb))
    sys.exit()

for i in range(len(sa))[::-1]:
    mb = 0
    lb = len(sb) - 1
    if len(sb) == 0 or sa[i] + sb[0] > k:
        print(len(sa))
        sys.exit()
    
    while lb - mb > 1:
        mid = (mb+lb)//2
        if c(mid):
            mb = mid
        else:
            lb = mid
    ans = max(ans, i+1+lb)

print(ans)

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

sa = [0]
sb = [0]

for i in range(n):
    sa.append(sa[i]+a[i])

for i in range(m):
    sb.append(sb[i]+b[i])

ans = 0
j = m


for i in range(n+1):
    if sa[i] > k:
        break
    while sa[i]+sb[j] > k:
        j -= 1
    ans = max(ans, i+j)

print(ans)

Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

Accepted