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):
# ABC C-Tsundoku
n,m,k = map(int,input().split())
an = list(map(int,input().split()))
bn = list(map(int,input().split()))

suma = [0]
sumb = [0]
a = 0
b = 0
for i in an:
    a += i
    suma.append(a)
for i in bn:
    b += i
    sumb.append(b)

res = [0]
l = m
for j in range(n+1):
    if k-suma[j] < 0:
        break
    while k-suma[j]-sumb[l] < 0 and l > 0:
        l -= 1
    res.append(j+l-1)
print(max(res))

# ABC C-Tsundoku
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

ans = 0
flag = False
for i in range(n+1):
    if flag == True:
        break
    for j in range(m+1):
        if sum(a[:i])+sum(b[:j])<=k and ans < i+j:
            ans = i+j
            flag = True
            break
print(ans)

# ABC C-Tsundoku
n,m,k = map(int,input().split())
an = list(map(int,input().split()))
bn = list(map(int,input().split()))

suma = [0]
sumb = [0]
a = 0
b = 0
for i in an:
    a += i
    suma.append(a)
for i in bn:
    b += i
    sumb.append(b)

res = [0]
for j in range(n+1):
    if k-suma[j] < 0:
        break
    for l in range(m+1):
        if k-suma[j]-sumb[l] > 0:
        res.append(j+l)
print(max(res))

# ABC C-Tsundoku
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

ans = 0
if sum(a)+sum(b) <= k:
    ans = n+m
    print(ans)
else:
    flag = False
    for i in range(n+1):
        if flag == True:
            break
        for j in range(m+1):
            if sum(a[:i])+sum(b[:j])<=k and ans < i+j:
                ans = i+j
                flag = True
                break
    print(ans)

# ABC C-Tsundoku
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

ans = 0
if sum(a)+sum(b) <= k:
    ans = n+m
    print(ans)
else:
    flag = False
    for i in range(n+1):
        if flag == True:
            break
        for j in range(m+1):
            if sum(a[:i])+sum(b[:j])<=k and ans < i+j:
                ans = i+j
                flag = True
                break
    print(ans)

# ABC C-Tsundoku
import sys
input = sys.stdin.readline

n,m,k = map(int,input().split())
an = list(map(int,input().split()))
bn = list(map(int,input().split()))

suma = [0]
sumb = [0]
a = 0
b = 0
for i in an:
    a += i
    suma.append(a)
for i in bn:
    b += i
    sumb.append(b)

res = [0]
l = m
for j in range(n+1):
    if k-suma[j] < 0:
        break
    while k-suma[j]-sumb[l] < 0 and l > 0:
        l -= 1
    res.append(j+l)
print(max(res))

Verdicts: Wrong Answer

Wrong Answer

Runtime Error

Wrong Answer

Wrong Answer

Accepted