TnT/Multi_CodeNet4Repair huggingface dataset:
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):
import itertools
import numpy as np 
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a = [0] + a
b = [0] + b
acc = list(itertools.accumulate(a))
bcc = list(itertools.accumulate(b))

acc = np.array(acc)
#print(acc)
bcc = np.array(bcc)

ans = 0

for i, val in enumerate(acc):
  if (val > k):
    break
  else:
    rest = k - val
    print(rest)
    for j, val2 in enumerate(bcc):
      if (val2 <= rest):
        ans = max(ans, j + i)
      else:
        break

print(ans)
  

import itertools
import numpy as np 
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
acc = list(itertools.accumulate(a))
bcc = list(itertools.accumulate(b))

acc = np.array(acc)
#print(acc)
bcc = np.array(bcc)

ans = 0

for i in acc:
  if (i > k):
    continue
  else:
    rest = k - i
    for j in bcc:
      if (j <= rest):
        ans = max(ans, j + i)
      else:
        break

print(ans)
  

import itertools
import numpy as np 
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
# -------------------
n, m, k = map(int, readline().split())
print(n)
a = list(map(int, readline().split()))
b = list(map(int, readline().split()))
a = [0] + a
b = [0] + b
acc = list(itertools.accumulate(a))
bcc = list(itertools.accumulate(b))

#acc = np.array(acc)
#print(acc)
#bcc = np.array(bcc)

ans = 0

for i, val in enumerate(acc):
  if (val > k):
    break
  else:
    rest = k - val
    #print(rest)
    for j, val2 in enumerate(bcc):
      if (val2 <= rest):
        ans = max(ans, j + i)
      else:
        break

print(ans)
  


import itertools
import numpy as np 
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
# -------------------
n, m, k = map(int, readline().split())
#print(n)
a = list(map(int, readline().split()))
b = list(map(int, readline().split()))
a = [0] + a
b = [0] + b
acc = list(itertools.accumulate(a))
bcc = list(itertools.accumulate(b))

#acc = np.array(acc)
#print(acc)
#bcc = np.array(bcc)

ans = 0
j = m
for i, val in enumerate(acc):
  if (val > k):
    break
  else:
    rest = k - val
    #print(rest)
    #j = m
    
    while (bcc[j] > rest):
      j -= 1

    ans = max(ans, j + i)


print(ans)

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted
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 = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]

if k < a[0] and k < b[0]:
    print(0)
    exit()

if sum(a) + sum(b) <= k:
    print(n+m)
    exit()

a_temp = a[0]
b_temp = b[0]
temp = 0
count = 0
hour = 0
i = 0
j = 0

while k > hour:
    
    count += 1
    if a_temp <= b_temp:
        hour += a_temp
        i += 1
        if i == len(a):
            a_temp = 10**10
        else:
            a_temp = a[i]
    else:
        hour += b_temp
        j += 1
        if j == len(b):
            b_temp = 10**10
        else:
            b_temp = b[i]

print(count)


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

A = [int(x) for x in input().split()]
B = [int(x) for x in 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)


Verdicts: Runtime Error

Accepted
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):
'''ABC172 C'''
import numpy as np
n,m,k = map(int,input().split())
a = np.array([int(i) for i in input().split()], dtype='int64')
b = np.array([int(i) for i in input().split()], dtype='int64')

a_c = np.zeros(n+1,dtype='int64')
a_c[1:] = np.cumsum(a)

b_c = np.zeros(m+1,dtype='int64')
b_c[1:] = np.cumsum(b)

a_c = a_c[a_c <= k]
b_c = b_c[b_c <= k]
ans = 0
for i,ai in enumerate(a_c):
    n = np.searchsorted(b_c, k - ai, side = 'right')
    ans = max(i + n, ans)
print(ans)

import numpy as np
n,m,k = map(int,input().split())
a = np.array([int(i) for i in input().split()], dtype='int64')
b = np.array([int(i) for i in input().split()], dtype='int64')


a_c = np.zeros(n+1,dtype='int64')
a_c[1:] = np.cumsum(a)

b_c = np.zeros(m+1,dtype='int64')
b_c[1:] = np.cumsum(b)

a_c = a_c[a_c <= k]
b_c = b_c[b_c <= k]

ans_l = np.searchsorted(b_c, k - a_c, side='right') - 1
ans_l += np.arange(len(a_c))
print(ans_l.max())

Verdicts: Wrong Answer

Accepted
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):
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**7)
import bisect
import heapq
import itertools
import math
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from math import gcd
from operator import add, itemgetter, mul, xor
def cmb(n,r,mod):
  bunshi=1
  bunbo=1
  for i in range(r):
    bunbo = bunbo*(i+1)%mod
    bunshi = bunshi*(n-i)%mod
  return (bunshi*pow(bunbo,mod-2,mod))%mod
mod = 10**9+7
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]







n,m,k = MI()
a = deque(LI())
b = deque(LI())
ans = 0
while k > 0 and len(a) + len(b) > 0:
    if len(a) > 0:
        book = a.popleft()
    if len(a) == 0:
        book = 10**10
    if len(b) > 0:
        book2 = b.popleft()
    if len(b) == 0:
        book2 = 10**10
    if book < book2:
        k -= book
        if k > 0:
            ans += 1
    if book > book2
        k -= book2
        if k > 0:
            ans += 1
print(ans)

#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**7)
import bisect
import heapq
import itertools
import math
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from math import gcd
from operator import add, itemgetter, mul, xor
def cmb(n,r,mod):
  bunshi=1
  bunbo=1
  for i in range(r):
    bunbo = bunbo*(i+1)%mod
    bunshi = bunshi*(n-i)%mod
  return (bunshi*pow(bunbo,mod-2,mod))%mod
mod = 10**9+7
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]







n,m,k = MI()
a = LI()
b = LI()
a_cum = [0]
b_cum = [0]
ans = 0
for i in range(1,n+1):
    a_cum.append(a[i-1]+a_cum[i-1])
for i in range(1,m+1):
    b_cum.append(b[i-1]+b_cum[i-1])
for i in range(m+1):
    K = k-b_cum[i]
    if K >= 0:
    
      j = bisect.bisect_right(a_cum, K) - 1
      ans = max(ans,i+j)
print(ans)



Verdicts: Runtime Error

Accepted
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()))
A=[0]*(n+1)
B=[0]*(m+1)
c = 0

for i in range(n):
    A[i+1] = A[i] + a[i]
for i in range(m):
    B[i+1] = B[i] + b[i]
#
for i in range(n+1):
    if A[i]>k:
        bookA=i-1
        timeA = A[i-1]
        break
else:
    bookA = n
    timeA = A[n]
    
for i in range(m+1):
    if B[i] >k:
        bookB = i-1
        timeB = B[i-1]
        break
else:
    bookB = m
    timeB = B[m]
#
"""
print(bookA,timeA,)
print(bookB,timeB)
if bookA == 0 and bookB == 0:
    print(0)
    exit()
"""
if bookA < bookB:
    time = timeB
    book = bookB
    for i in range(n+1):
        if k-time < A[i]:
            break
        c = i
    else:
        c = n
    book += c 

elif bookA > bookB:
    book = bookA
    time = timeA
    for i in range(m+1):
        if k-time < B[i]:
            break
        c = i
    else:
        c = m
    book += c

else:
    if timeA > timeB:
        time = timeB
        book = bookB
        for i in range(n+1):
            if k-time < A[i]:
                break
            c = i
        book += c
    elif timeB > timeA:
        time = timeA
        book = bookA
        for i in range(m+1):
            if k-time < B[i]:
                break
            c = i
        book += c
        print(c)
    else:
        if A[bookA-1] > B[bookB-1]:
            book = bookB-1
            for i in range(n+1):
                if A[i] > k:
                    break
                c = i
            book += c
        elif A[bookA-1] < B[bookB-1]:
            book = bookA-1
            for i in range(m+1):
                if B[i] > k:
                    break
                c = i
            book += c
        else:
            book = bookA
            for i in range(m+1):
                if k-timeA < B[i]:
                    book += i-1
            else:
                book += m
if book < 0:
    print(0)
else:
    print(book)

n,m,k=map(int, input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))


cumA = [0]*(n+1)
for i in range(n):
    cumA[i+1] = cumA[i] + A[i]

cumB = [0]*(m+1)
for i in range(m):
    cumB[i+1] = cumB[i] + B[i]

ans = 0
j = m

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

Verdicts: Wrong Answer

Accepted
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_l = list(map(int, input().split()))
b_l = list(map(int, input().split()))

i_l, j_l = [0], [0]

best0 = M
ans = 0

for i in range(N):
    i_l.append(i_l[i] + a_l[i])

for i in range(M):
    j_l.append(j_l[i] + b_l[i])

# for j in range(M):

#     if total > K:

#         break
#     elif total == K:

#     else:
#         continue

for k in range(N+1):
    if i_l[i] > K:
        break
    while i_l[k] + j_l[best0] > K:
        best0 -= 1
    ans = max(ans, k+best0)
print(ans)
    

N, M, K = map(int, input().split())
a_l = list(map(int, input().split()))
b_l = list(map(int, input().split()))

i_l, j_l = [0], [0]

best0 = M
ans = 0

for i in range(N):
    i_l.append(i_l[i] + a_l[i])

for i in range(M):
    j_l.append(j_l[i] + b_l[i])

# for j in range(M):

#     if total > K:

#         break
#     elif total == K:

#     else:
#         continue

for k in range(N+1):
    if i_l[k] > K:
        break
    while i_l[k] + j_l[best0] > K:
        best0 -= 1
    ans = max(ans, k+best0)
print(ans)
    

Verdicts: Runtime Error

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

time = 0
count = -1
saidaicho = len(A) + len(B)
while time <= K:
    time += max(A[0], B[0])
    count += 1

    if A[0] > B[0]:
        A.pop(0)
    else:
        B.pop(0)

    if len(A) == 0:
        A.append(0)
    elif len(B) == 0:
        B.append(0)

    if count == saidaicho:
        break
print(count)


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

ruiA = [0]
ruiB = [0]
for i in range(N):
    ruiA.append(ruiA[-1] + A[i])
for i in range(M):
    ruiB.append(ruiB[-1] + B[i])

MAX = 0
i = 0
for j in range(M, -1, -1):
    if ruiA[i] + ruiB[j] <= K:
        MAX = max(MAX, i+j)
        best = j
    break
    
for i in range(1, N+1):
    for j in range(best, -1, -1):
        if ruiA[i] + ruiB[j] <= K:
            MAX = max(MAX, i+j)
        break


print(MAX)


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

ruiA = [0]
ruiB = [0]
for i in range(N):
    ruiA.append(ruiA[-1] + A[i])
for i in range(M):
    ruiB.append(ruiB[-1] + B[i])

MAX = 0
j = M

for i in range(N+1):
    if ruiA[i] > K:
        break
    while ruiA[i] + ruiB[j] > K:
        j -= 1
    MAX = max(MAX, i+j)

print(MAX)


Verdicts: Wrong Answer

Runtime Error

Accepted
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 = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

total = 0
maxb = 0
for i in range(N):
    if total + A[i] <= K:
        total += A[i]
        maxb += 1
    else:
        break

i = maxb - 1
for j in range(M):

    if total + B[j] <= K:
        total += B[j]
    else:
        if i == -1:
            break
        total -= A[i]
        i -= 1
        j -= 1

    if maxb < i + j + 2:
        maxb = i + j + 2
print(maxb)


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

total = 0
Asum = sum(A)
nA = len(A)
Bsum = 0
ans = 0
for nB in range(len(B) + 1):
    if nB != 0:
        Bsum += B[nB-1]
    if Bsum > K:
        break
    while Asum + Bsum > K:
        nA -= 1
        Asum -= A[nA]
    ans = max(nA + nB, ans)

print(ans)


Verdicts: Wrong Answer

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


Verdicts: Runtime Error

Accepted
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()))
Asum = [0]
Bsum = [0]
a = 0
b = 0
for i in range(N):
    a += A[i]
    Asum.append(a)
for i in range(M):
    b += B[i]
    Bsum.append(b)
Asum.append(0)
Bsum.append(0)
res, j = 0, 0
for i in range(N+1):
    if Asum[i] > K:
        break
    while Asum[i] + Bsum[j] > K:
            j -= 1
    res = max(res,i+j)
print(res)

N, M, K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
Asum = []
Bsum = []
for i in range(N):
    a = 0
    a += A[i]
    Asum.append(a)
for i in range(M):
    b = 0
    b += B[i]
    Bsum.append(b)
Asum.append(0)
Bsum.append(0)
res = 0
for i in range(-1,N-1):
    for j in range(-1,M-1):
        if Asum[i] + Bsum[j] <= K:
           res = max(res,(i+j+2))
        else:
           break
print(res)

N, M, K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
Asum = [0]
Bsum = [0]
a = 0
b = 0
for i in range(N):
    a += A[i]
    Asum.append(a)
for i in range(M):
    b += B[i]
    Bsum.append(b)
Asum.append(0)
Bsum.append(0)
res, j = 0, M
for i in range(N+1):
    if Asum[i] > K:
        break
    while Asum[i] + Bsum[j] > K:
        j -= 1
    res = max(res,i+j)
print(res)

Verdicts: Wrong Answer

Wrong Answer

Accepted
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_li = list(map(int, input().split()))
b_li = list(map(int, input().split()))

a_li = [0] + a_li
b_li = [0] + b_li

time = 0
ans = 0
a = 0
temp = 0

a_wa = [0] * (n+10)
b_wa = [0] * (m+10)

s = 0
for i in range(n+1):
    s += a_li[i]
    a_wa[i] = s

s = 0
for i in range(m+1):
    s += b_li[i]
    b_wa[i] = s
    

for i in range(n+1):
    for j in range(min(ans-temp, m), m+1):
        time = a_wa[i] + b_wa[j]
        if time <= k:
            ans = max(ans, i+j)
            temp = i
        else:
            break
            
print(ans)

n,m,k = map(int, input().split())
a_li = list(map(int, input().split()))
b_li = list(map(int, input().split()))

a_li = [0] + a_li
b_li = [0] + b_li

time = 0
ans = 0
a = 0
temp = 0

a_wa = [0] * (n+10)
b_wa = [0] * (m+10)

s = 0
for i in range(n+1):
    s += a_li[i]
    a_wa[i] = s

s = 0
for i in range(m+1):
    s += b_li[i]
    b_wa[i] = s
    

for i in range(n+1):
    for j in range(max(min(temp-i, m), 0), m+1):
        time = a_wa[i] + b_wa[j]
        if time <= k:
            ans = max(ans, i+j)
            temp = ans
        else:
            break
            
print(ans)


Verdicts: Wrong Answer

Accepted
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):
from itertools import accumulate
from bisect import bisect_left

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

a = [0] + list(accumulate(A))
b = [0] + list(accumulate(B))

result = 0
for i in range(N):
    t = K - a[i]
    if t < 0:
        break
    j = bisect_left(b, t)
    if b[j] == t:
        result = max(result, i + j + 1)
    else:
        result = max(result, i + j)
print(result)



from itertools import accumulate
from bisect import bisect_right

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

a = [0] + list(accumulate(A))
b = [0] + list(accumulate(B))

result = 0
for i in range(N + 1):
    if a[i] > K:
        break
    j = bisect_right(b, K - a[i])
    result = max(result, i + j - 1)
print(result)


Verdicts: Runtime Error

Accepted
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()))
  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)


n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
A=[0]
B=[0]
for i in range(n):
    A.append(a[i]+A[i])
for j in range(m):
    B.append(b[j]+B[j])

i=0
j=m
ans=0
tmp=0
while(i<n+1 and j>=0):
    if(k>=A[i]):
        tmp=k-A[i]
        if(tmp-B[j]>=0):
            ans=max(ans,i+j)
            i+=1
        else:
            j-=1
    else:
        break
print(ans)
        
    

            


Verdicts: Runtime Error

Accepted
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()))
cnt=0
while cnt==n+m:
  if len(B)==0:
    k-=A[0]
    del A[0]
    cnt+=1
  elif len(A)==0:
    k-=B[0]
    del B[0]
    cnt+=1
  elif A[0]<=B[0] and k>A[0]:
    k-=A[0]
    del A[0]
    cnt+=1
  elif B[0]<A[0] and k>B[0]:
    k-=B[0]
    del B[0]
    cnt+=1
  else:
    break
print(cnt)

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

b2=[]
b2.append(0)
for i in range(1,m+1):
  b2.append(b2[i-1]+b[i-1])
a.insert(0,0)
cnt=0
a_sum=0
for i in range(n+1):
  j=m
  a_sum+=a[i]
  while True:
    if k>=a_sum+b2[j]:
      cnt=max(cnt,i+j)
      m=j
      break
    j-=1
    if j <0:
      break
print(cnt)

Verdicts: Wrong Answer

Accepted
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()))

N,M,K =map(int,"5 7 100".split())
A = [10,10,20,30,3]
B = [3,9,30,20,1,7,20]


A_min = [0]
for i in range(N):
  A_min.append(A_min[i]+A[i])
B_min = [0]
for i in range(M):
  B_min.append(B_min[i]+B[i])


ans = 0
B_len = M
for i in range(len(A_min)):
  if A_min[i] > K:
    break
  while B_min[B_len] > K - A_min[i]:
    B_len -= 1
  ans = max(ans,i+B_len)
print(ans)

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


A_min = [0]
for i in range(N):
  A_min.append(A_min[i]+A[i])
B_min = [0]
for i in range(M):
  B_min.append(B_min[i]+B[i])


ans = 0
B_len = len(B_min)
for i in range(len(A_min)):
  if A_min[i] > K:
    break
  while true:
    if B_min[B_len] > K - A_min[i]:
      break
    ans = max(ans,i+B_len)

print(ans)

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


A_min = [0]
for i in range(N):
  A_min.append(A_min[i]+A[i])
B_min = [0]
for i in range(M):
  B_min.append(B_min[i]+B[i])


ans = 0
B_len = len(B_min)
for i in range(len(A_min)):
  if Amin[i] > K:
    break
  while true:
    if B_min[B_len] > K - A_min[i]:
      break
    ans = max(ans,i+B_len)

print(ans)

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


A_min = [0]
for i in range(N):
  A_min.append(A_min[i]+A[i])
B_min = [0]
for i in range(M):
  B_min.append(B_min[i]+B[i])


ans = 0
B_len = M
for i in range(len(A_min)):
  print("i=",str(i))
  if A_min[i] > K:
    break
  while B_min[B_len] > K - A_min[i]:
    print("B_len=",str(B_len))
    print("A_min=",str(A_min[i]))
    print("B_min=",str(B_min[B_len]))
    ans = max(ans,i+B_len)
    B_len -= 1
print(ans)

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


A_min = [0]
for i in range(N):
  A_min.append(A_min[i]+A[i])
B_min = [0]
for i in range(M):
  B_min.append(B_min[i]+B[i])


ans = 0
B_len = M
for i in range(len(A_min)):
  if A_min[i] > K:
    break
  while B_min[B_len] > K - A_min[i]:
    B_len -= 1
  ans = max(ans,i+B_len)
print(ans)

Verdicts: Wrong Answer

Runtime Error

Runtime Error

Wrong Answer

Accepted
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):
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())))

if sum(A) + sum(B) < K:
    print(N + M)
    exit()

ans = 0

while K > 0:
    if len(A) != 0:
        # if len(B) == 0 or A[0] <= B[0]:
        if len(B) == 0 or sum(A) <= sum(B):
            if A[0] <= K:
                K -= A.popleft()
                ans += 1
                continue
    if len(B) != 0:
        # if len(A) == 0 or A[0] >= B[0]:
        if len(A) == 0 or sum(A) >= sum(B):
            if B[0] <= K:
                K -= B.popleft()
                ans += 1
                continue

print(ans)


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


A_sum, B_sum = [0], [0]
for i, a in enumerate(A):
    A_sum.append(A_sum[i] + a)
for i, b in enumerate(B):
    B_sum.append(B_sum[i] + b)

ans = 0
j = M





for i in range(N+1):
    if A_sum[i] > K:
        break
    while B_sum[j] > K - A_sum[i]:
        j -= 1
    ans = max(ans, i+j)

print(ans)


Verdicts: Time Limit Exceeded

Accepted
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):
from functools import lru_cache

ri = lambda S: [int(v) for v in S.split()]


def rii():
    return ri(input())


N, M, K = rii()
A = rii()
B = rii()

i = j = 0


@lru_cache(None)
def dp(i, j, k):
    ki = kj = mki = mkj = 0

    if i < N:
        Ki = k - A[i] if A[i] <= k else 0
        mki = 1 + dp(i + 1, j, Ki) if Ki >= 0 else 0
    if j < M:
        kj = k - B[j] if B[j] <= k else 0
        mkj = 1 + dp(i, j + 1, kj) if kj >= 0 else 0

    return max(mki, mkj)


print(dp(0, 0, K))
#print(dp.cache_info())


ri = lambda S: [int(v) for v in S.split()]


def rii():
    return ri(input())


N, M, K = rii()
A = rii()
B = rii()

i = j = 0


def dp(i, j, k):
    ki = kj = mki = mkj = 0

    if i < N:
        Ki = k - A[i] if A[i] <= k else 0
        mki = 1 + dp(i + 1, j, Ki) if Ki >= 0 else 0
    if j < M:
        kj = k - B[j] if B[j] <= k else 0
        mkj = 1 + dp(i, j + 1, kj) if kj >= 0 else 0

    return max(mki, mkj)


print(dp(0, 0, K))


ri = lambda S: [int(v) for v in S.split()]


def rii():
    return ri(input())


N, M, K = rii()
A = rii()
B = rii()

i = j = 0


def dp(i, j, k):
    print(i, j, k)
    ki = kj = mki = mkj = 0

    if i < N:
        Ki = k - A[i] if A[i] <= k else 0
        mki = 1 + dp(i + 1, j, Ki) if Ki >= 0 else 0
    if j < M:
        kj = k - B[j] if B[j] <= k else 0
        mkj = 1 + dp(i, j + 1, kj) if kj >= 0 else 0

    return max(mki, mkj)


print(dp(0, 0, K))


from itertools import accumulate
from bisect import bisect_left

ri = lambda S: [int(v) for v in S.split()]


def rii():
    return ri(input())


N, M, K = rii()
A = rii()
B = rii()

i = j = 0

pA = [0] + list(accumulate(A))
pB = [0] + list(accumulate(B))

ans = 0
for i, a in enumerate(pA):
    br = 0
    if K >= a:
        r = K - a
        br = i
    
    if r:
        j = bisect_left(pB, r)
        if j != len(pB):
            if pB[j] > r:
                j -= 1
            br += j
    
    ans = max(ans, br)

print(ans)

Verdicts: Runtime Error

Runtime Error

Runtime Error

Accepted
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()))
p = 0
z = 0
i = 0
j = 0

while p < k:
    if a[i] < b[j]:
        p += a[i]
        z += 1
        i += 1
    elif a[i] > b[j]:
        p += b[j]
        z += 1
        j += 1
    else:
        if a[i+1] < b[j+1]:
            p += a[i]
            z += 1
            i += 1
        elif:
            p += b[j]
            z += 1
            j += 1

print(z)

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

x = 0
for i in range(n):
    x += a[i]
    a[i] = x

x = 0
for i in range(m):
    x += b[i]
    b[i] = x

x = 0
for i in range(n):
    x = a[i]
    if x > k:
        x = a[i-1]
        ans = i
        j = i-2
        break
    if i + 1 == n:
        ans = n
        j = i-1

y = 0
for i in range(m):
    y = b[i]
    if x + y > k:
        while x + y > k and j >= 0:
            x = b[j]
            j -= 1
    if x + y <= k:
        ans = max(ans,i+j+2)

print(ans)


n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
p = 0
i = 0
j = 0
while p < k:
    if a[i] < b[j]:
        p += 1
        i += 1
    elif a[i] > b[j]:
        p += 1
        j += 1
    else:
        if a[i+1] < b[j+1]:
            p += 1
            i += 1
        else:
            p += 1
            j += 1

print(p)

n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = [0]*(n+1)
d = [0]*(m+1)
for i in range(n):
    c[i+1] = a[i]+c[i]
for i in range(m):
    d[i+1] = b[i]+d[i]
for i in range(m+1)[::-1]:
    if d[i] <= k:
        x = i
        break
ans = x
for i in range(1,n+1):
    while c[i] + d[x] > k:
        if x >= 1:
            x -= 1
        else:
            break
    if c[i] + d[x] <= k:
        ans = max(ans,i+x)
print(ans)

Verdicts: Runtime Error

Runtime Error

Runtime Error

Accepted
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):
import bisect
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]

I = bisect.bisect_right(a, k)
ans = bisect.bisect_right(b, k)
li = list(range(I))
li = li[::-1]
for i in li:
    tmp = bisect.bisect_right(b, k-a[i])
    if a[i] + b[tmp-1] <= k && tmp != 0:
        ans = max(ans, i+tmp+1)

print(ans)

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

a2 = [0] * (n + 1)
b2 = [0] * (m + 1)
for i in range(0, n):
    a2[i+1] = a[i] + a2[i]
for i in range(0, m):
    b2[i+1] = b[i] + b2[i]

ans = 0
for i in range(n+1):
    tmp = bisect.bisect_right(b2, k-a2[i]) - 1
    if a2[i] + b2[tmp] <= k and tmp >= 0:
        ans = max(ans, i+tmp)

print(ans)

Verdicts: Runtime Error

Accepted
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 main():
    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):
        a.append(b[i] + B[i])

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

        while a[i] + b[j] > K:
            j -= 1

        ans = max(ans, i + j)

    print(ans)


if __name__ == "__main__":
    main()


def main():
    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 a[i] + b[j] > K:
            j -= 1

        ans = max(ans, i + j)

    print(ans)


if __name__ == "__main__":
    main()


Verdicts: Runtime Error

Accepted
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()))

p, q = [0], [0]
for i in range(n):
	p.append(p[i] + a[i])
for i in range(m):
	q.append(q[i] + b[i])

j, ans = m, 0
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)

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

p, q = [0], [0]
for i in range(n):
	p.append(p[i] + a[i])
for i in range(m):
	q.append(q[i] + b[i])

j, ans = m, 0
for i in range(n+1):
	if p[i] > k:
		break

	while q[j] > k - p[i]:
		j -= 1

	ans = max(ans, i+j)

print(ans)

Verdicts: Runtime Error

Accepted
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()))
c=0
import numpy as np
A=np.array(A).cumsum()
B=np.array(B).cumsum()
for i in range(N):
  d=K-A[i]
  if d>=0:
    for j in reversed(range(M)):
      if d>=B[j]:
        if c<i+j+2:
          c=i+j+2
        M=j+1
        break
    if d<B[0]:
      c=i+1
  else:
    for j in reverse(range(M)):
      if K-B[j]>=0:
        if c<j+1:
          c=j+1
        break
    break
print(c)

N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
c=0
A.insert(0,0)
B.insert(0,0)
import numpy as np
A=np.array(A).cumsum()
B=np.array(B).cumsum()

for i in range(N+1):
  d=K-A[i]
  for j in reversed(range(M+1)):
    if d-B[j]>=0:
      if c<i+j:
        c=i+j
      M=j
      break
print(c)

Verdicts: Runtime Error

Accepted
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 resolve():
    N, M, K = list(map(int, input().split()))
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    read = deque()

    while sum(read) <= K:
        if len(A) == 0 and len(B) == 0:
            break

        if len(A) == 0:
            if sum(read) + B[0] <= K:
                read.append(B[0])
            B.pop(0)
            continue

        if len(B) == 0:
            if sum(read) + A[0] <= K:
                read.append(A[0])
            A.pop(0)
            continue

        if A[0] < B[0]:
            if sum(read) + A[0] <= K:
                read.append(A[0])
            A.pop(0)
        else:
            if sum(read) + B[0] <= K:
                read.append(B[0])

            B.pop(0)

    print(len(read))


resolve()

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

    ans = 10 ** 10
    t = 0

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

resolve()

Verdicts: Runtime Error

Accepted
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()))

sum_A = [0] * (N + 1)
sum_B = [0] * (M + 1)

for a in range(1, N + 1):
    sum_A[a] = sum_A[a - 1] + A[a - 1]
for b in range(1, M + 1):
    sum_B[b] = sum_B[b - 1] + B[b - 1]

count = 0

print(sum_A)
print(sum_B)
last_index = M

for a in range(len(sum_A)):
    print("----------------------")
    print("a", a)
    if sum_A[a] >= K:
        count = max(count, a)
        break
    now = sum_A[a]
    rest = K - now
    print("last_index", last_index)
    

    while True:
        if last_index < 0:
            able = 0
            break
        if sum_B[last_index] > rest:
            last_index -= 1
        else:
            able = last_index
            break

    print("now", now, "rest", rest, "able", able)
    print("今回の最大countは", "a + able = ", a + able)
    count = max(count, a + able)
    print("これまでの最大count", count)

print(count)


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

sum_A = [0] * (N + 1)
sum_B = [0] * (M + 1)

for a in range(1, N + 1):
    sum_A[a] = sum_A[a - 1] + A[a - 1]
for b in range(1, M + 1):
    sum_B[b] = sum_B[b - 1] + B[b - 1]

count = 0

# print(sum_A)

last_index = M

for a in range(len(sum_A)):
    # print("----------------------")
    # print("a", a)
    if sum_A[a] > K:
        count = max(count, a - 1)
        break
    elif sum_A[a] == K:
        count = max(count, a)
    now = sum_A[a]
    rest = K - now
    
    

    while True:
        if last_index < 0:
            able = 0
            break
        if sum_B[last_index] > rest:
            last_index -= 1
        else:
            able = last_index
            break

    
    
    count = max(count, a + able)
    

print(count)


Verdicts: Wrong Answer

Accepted
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):
#include<bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define EPS (1e-10)

using namespace std;

int main(int argc, char *argv[]) {

	long N,M; cin >> N >> M;
	long K; cin >> K;
	
	vector<long> A(N+1,0);
	for (int i = 1; i <= N; i++) {
		int a; cin >> a;
		A[i] = A[i-1] + a;
	}

	vector<long> B(M+1,0);
	for (int i = 1; i <= M; i++) {
		int b; cin >> b;
		B[i] = B[i-1] + b;
	}

	long ans = 0;
	long best = M;
	for (int i = 1; i <= N; i++) {
		if (A[i] > K) {
			break;	
		}
		
		while (1 < best and B[best] > K - A[i]) {
			best--;		
		}
		ans = max(ans, i+best);

	}
	cout << ans << endl;



	return 0;
}


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)

Verdicts: Runtime Error

Accepted