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())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

b_li = [0]
b_ = 0

for B_ in B:
    b_ = b_ + B_
    b_li.append(b_)

book_max = 0
book_cnt_a = 0
book_cnt_ab = 0
a_ = 0
book_cnt_ab = M

for i in range(N+1):
    while (b_li[book_cnt_ab-1] + a_) > K:
        book_cnt_ab = book_cnt_ab - 1
        if book_cnt_ab == 0: break
    if (book_max <= book_cnt_ab + book_cnt_a):
            book_max = book_cnt_ab + book_cnt_a
    book_cnt_a = book_cnt_a + 1
    if i >= N: break
    a_ = a_ + A[i]

print(book_max)



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

book_max = 0
book_cnt = 0

Asum = 0
for ia in range(N+1):
    Bsum = 0
    for ib in range(M+1):
        if K < (Asum + Bsum): break
        book_cnt = book_cnt + 1
        if book_max < (book_cnt - 0):
            book_max = book_cnt
        if ib == M: break
        Bsum = Bsum + B[ib]
    book_cnt = ia + 1
    if book_max < (book_cnt - 0):
        book_max = book_cnt
    if ia == N: break
    Asum = Asum + A[ia]

print(book_max)


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

a_li = [0]
a_ = 0
b_li = [0]
b_ = 0

for A_ in A:
    a_ = a_ + A_
    a_li.append(a_)

for B_ in B:
    b_ = b_ + B_
    b_li.append(b_)

book_max = 0
book_cnt_a = 0
book_cnt_ab = 0

for a_ in a_li:
    book_cnt_ab = M
    for b_ in b_li.reverse():
        if (a_ + b_) < K:
            if (book_max <= book_cnt_ab + book_cnt_a):
                book_max = book_cnt_ab + book_cnt_a
            break
        book_cnt_ab = book_cnt_ab - 1
    book_cnt_a = book_cnt_a + 1

print(book_max)


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

b_li = [0]
b_ = 0

for B_ in B:
    b_ = b_ + B_
    b_li.append(b_)

book_max = 0
book_cnt_a = 0
book_cnt_ab = 0
a_ = 0
book_cnt_ab = M

for i in range(N+1):
    while (b_li[book_cnt_ab-1] + a_) > K:
        book_cnt_ab = book_cnt_ab - 1
        if book_cnt_ab < 0: break
    if book_cnt_ab < 0: break
    if (book_max <= book_cnt_ab + book_cnt_a):
            book_max = book_cnt_ab + book_cnt_a
    book_cnt_a = book_cnt_a + 1
    if i >= N: break
    a_ = a_ + A[i]

print(book_max)


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

book_max = 0
book_cnt = 0

Asum = 0
for ia in range(N+1):
    Bsum = 0
    for ib in range(M+1):
        if K < (Asum + Bsum): break
        if ib == M: break
        Bsum = Bsum + B[ib]
        book_cnt = book_cnt + 1
        if book_max < (book_cnt - 0):
            book_max = book_cnt
    if ia == N: break
    Asum = Asum + A[ia]
    book_cnt = ia + 1
    if book_max < (book_cnt - 0):
        book_max = book_cnt

print(book_max)

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

b_li = [0]
b_ = 0

for B_ in B:
    b_ = b_ + B_
    b_li.append(b_)

book_max = 0
book_cnt_a = 0
book_cnt_ab = 0
a_ = 0
book_cnt_ab = M

for i in range(N+1):
    while (b_li[book_cnt_ab-1] + a_) > K:
        book_cnt_ab = book_cnt_ab - 1
    if (book_max <= book_cnt_ab + book_cnt_a):
            book_max = book_cnt_ab + book_cnt_a
    book_cnt_a = book_cnt_a + 1
    if i >= N: break
    a_ = a_ + A[i]

print(book_max)


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

Asum_li = [0]
Asum = 0
Bsum_li = [0]
Bsum = 0

for A_ in A:
    Asum = Asum + A_
    Asum_li.append(Asum)

for B_ in B:
    Bsum = Bsum + B_
    Bsum_li.append(Bsum)

cnt_max = 0
cnt_b = M

for cnt_a in range(N+1):

    if Asum_li[cnt_a] > K : break

    while (Bsum_li[cnt_b] + Asum_li[cnt_a]) > K:
        cnt_b = cnt_b - 1
        if cnt_b < 0: break

    if (cnt_max < cnt_a + cnt_b): cnt_max = cnt_a + cnt_b


print(cnt_max)



Verdicts: Runtime Error

Wrong Answer

Runtime Error

Wrong Answer

Wrong Answer

Runtime Error

Accepted