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 as it
def main():
    n,m,k=map(int,input().split())
    a = list(it.accumulate(map(int, input().split())))
    b = list(it.accumulate(map(int, input().split())))
    ans = []
    for A in range(n-1,-1,-1):
        print("A", A)
        aa = a[A]
        Kaa = k-aa
        for B in range(m-1,-1,-1):
            print("B", B)
            if b[B] <= Kaa:
                ans.append(A+B+2)
                break
    print(max(ans) if len(ans) > 0 else 0)
    
if __name__ == '__main__':
    main()

import itertools as it
def main():
    n,m,k=map(int,input().split())
    a = [0]
    a.extend(it.accumulate(map(int, input().split())))
    b = [0]
    b.extend(it.accumulate(map(int, input().split())))
    
    ans = 0
    M = m
    for A in range(n+1):
        aa = a[A]
        Kaa = k-aa
        if Kaa < 0:
            break
        for B in range(M,-1,-1):
            if b[B] <= Kaa:
                ans = max(ans, A+B)
                M = B
                break
    print(ans)

if __name__ == '__main__':
    main()

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):
# -*- coding: utf-8 -*-
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

ans=0
T=0
for i in range(N):
    T+=A[i]
    if T > K:
        T-=A[i]
        ans-=1
        break
    else:
        ans+=1
R=[]
R.append(ans)
n=ans
m=0
while(1):
    while(1):
        if m>=M: break
        T+=B[m]
        
        if T > K:
            T-=B[m]
            break
        else:
            ans+=1
            R.append(ans)
            m+=1
            
    n-=1
    if n<0: break
    T-=A[n]
    ans-=1
    

print(max(R))

# -*- coding: utf-8 -*-
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

ans=0
T=0
for i in range(N):
    T+=A[i]
    if T > K:
        T-=A[i]
        break
    else:
        ans+=1
R=[]
R.append(ans)
n=ans
m=0
while(1):
    while(1):
        if m>=M: break
        T+=B[m]
        
        if T > K:
            T-=B[m]
            break
        else:
            ans+=1
            R.append(ans)
            m+=1
            
    n-=1
    if n<0: break
    T-=A[n]
    ans-=1
    

print(max(R))

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

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


num = 0
J = M
for i in range(N+1):
    if A_sum[i] > K:
        break
    for j in (J,0,-1):
        if A_sum[i] + B_sum[j] <= K:
            if num < i+j:
                num = i+j
            J = j
            break

print(num)

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

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


num = 0
J = M
for i in range(N+1):
    if A_sum[i] > K:
        break
    for j in (J,-1,-1):
        if A_sum[i] + B_sum[j] <= K:
            if num < i+j:
                num = i+j
            J = j
            break

print(num)


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

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

num = 0
J = M
for i in range(N+1):
    if A_sum[i] > K:
        break
    for j in reversed(range(J+1)):
        if A_sum[i] + B_sum[j] <= K:
            if num < i+j:
                num = i+j
            J = j
            break

print(num)


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):
import sys
input = sys.stdin.readline
from collections import deque
def main():
    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    i, j = 0, 0
    while K > 0:
        print(i,j)
        if i == N:
            if j != M:
                read = B[j]
                if K >= read:
                    K -= read
                    j += 1
                else:
                    break
            else:
                i = N
                j = M
                break

        elif j == M:
            if i != N:
                read = A[i]
                if K >= read:
                    K -= read
                    i += 1
                else:
                    break
            else:
                i = N
                j = M
                break
        else:
            if A[i] >= B[j]:
                read = B[j]
                if K >= read:
                    K -= read
                    j += 1
                else:
                    break
            else:
                read = A[i]
                if K >= read:
                    K -= read
                    i += 1
                else:
                    break
    print(i+j)

if __name__ == '__main__':
    main()

import sys
input = sys.stdin.readline
from collections import deque
def main():
    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    As = [0]*(N+1)
    Bs = sum(B)
    As[0] = 0
    for i in range(1,N):
        As[i] = As[i-1] + A[i-1]
    T = K
    j = M 
    ans = 0
    for i in range(N):
        T = K - A[i]
        if T < 0:
            break
        while Bs > T:
            j -= 1
            Bs -= B[j]
        ans = max(ans, i+j+1)
    print(ans)

if __name__ == '__main__':
    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 b[j] > K - a[i]:
    j -= 1
  ans = max(ans, i + j)
print(ans)

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):
#C
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
asum=[0]
bsum=[0]
for i in range(n):
    asum.append(asum[-1]+a[i])
for i in range(m):
    bsum.append(bsum[-1+b[i]])
ans=0
for i in range(n+1):
    if asum[i]>0:
        break
    while asum[i]+bsum[m]>0 and m>0:
        m-=1
    ans=(ans,i+m)
print(ans)

n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
asum=[0]
bsum=[0]
for i in range(n):
    asum.append(asum[-1]+a[i])
for i in range(m):
    bsum.append(bsum[-1]+b[i])
ans=0
for i in range(n+1):
    if asum[i]>k:
        break
    while asum[i]+bsum[m]>k and m>0:
        m-=1
    ans=max(ans,i+m)
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_sum = [0]
for i in range(n):
  a_sum.append(a[i] + a_sum[i])
b_sum = [0]
for i in range(m):
  b_sum.append(b[i] + b_sum[i])

ans = 0
for i in range(n+1):
  if a[i] > k:
    break
  for j in range(m+1):
    if a_sum[i] + b_sum[j] <= k:
      ans = max(ans, i + j)
    else:
      break
print(ans)

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

a_sum = [0]
for i in range(n):
  a_sum.append(a[i] + a_sum[i])
b_sum = [0]
for i in range(m):
  b_sum.append(b[i] + b_sum[i])
  
ans = 0
j = m
for i in range(n+1):
  if a_sum[i] > k:
    break
  while a_sum[i] + b_sum[j] > k:
    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):
from itertools import accumulate

N, M, K = map(int, input().split())
a = list(accumulate(int(i) for i in input().split(), initial=0))
b = list(accumulate(int(i) for i in input().split(), initial=0))

cnt = 0
best0 = M
for i in range(N+1):
    ai = a[i]
    for j in range(best0, -1, -1):
        bj = b[j]
        if ai + bj <= K:
            cnt = max(cnt, i + j)
            best0 = j
            break

print(cnt)

from itertools import accumulate

N, M, K = map(int, input().split())
a = [0] + list(accumulate(int(i) for i in input().split()))
b = [0] + list(accumulate(int(i) for i in input().split()))

cnt = 0
best0 = M
for i in range(N+1):
    ai = a[i]
    for j in range(best0, -1, -1):
        bj = b[j]
        if ai + bj <= K:
            cnt = max(cnt, i + j)
            best0 = j
            break

print(cnt)

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):
# coding:utf-8
import itertools
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
j = m

aa = [0] + list(itertools.accumulate(a))
bb = [0] + list(itertools.accumulate(b))
#print(aa)
#print(bb)



for i, a_item in enumerate(a):
    if a_item > k:
        break
    while a_item + b[j] > k:
        j -= 1
    ans = max(i + j, ans)
print(ans)


# coding:utf-8
import itertools
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
j = m

aa = [0] + list(itertools.accumulate(a))
bb = [0] + list(itertools.accumulate(b))
# print(aa)
# print(bb)



for i, a_item in enumerate(aa):
    if a_item > k:
        break
    while a_item + bb[j] > k:
        j -= 1
    ans = max(i + j, ans)
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):
import numpy

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

acc_a = [0]
for i in range(N):
    acc_a.append(acc_a[i] + A[i])

acc_b = [0]
for i in range(M):
    acc_b.append(acc_b[i] + B[i])

acc_a = numpy.array(acc_a)
acc_b = numpy.array(acc_b)

currentMax = 0
for j in range(M + 1):
    tB = acc_b[j]
    remain = K - tB
    # print('-----------')
    
    if remain < 0:
        
        break

    print(numpy.where(acc_a < remain)[0])
    if len(numpy.where(acc_a < remain)[0]) != 0:
        readable = numpy.where(acc_a <= remain)[0][-1]

        
        
        currentMax = max(currentMax, j + readable)

print(currentMax)

import numpy

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

acc_a = [0]
for i in range(N):
    acc_a.append(acc_a[i] + A[i])

acc_b = [0]
for i in range(M):
    acc_b.append(acc_b[i] + B[i])

acc_a = numpy.array(acc_a)
acc_b = numpy.array(acc_b)

currentMax = 0
bnum = M
for anum in range(N + 1):
    if acc_a[anum] > K:
        break

    while True:
        if acc_b[bnum] > K - acc_a[anum]:
            bnum = bnum - 1 
        else:
            break

    currentMax = max(currentMax, anum + bnum)


print(currentMax)

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):
# -*- coding: utf-8 -*-
n, m, k = map(int, input().split())

alist = input().split()
blist = input().split()

print(alist)
print(blist)

work = k
acount = 0
while (acount < n) and (work >= int(alist[acount])):
    work -= int(alist[acount])
    acount += 1

maxCount = acount
bCount = 0
for num in range(0, acount):
    if (num > 1):
        work += int(alist[acount-num])

    while (bCount < m) and (work >= int(blist[bCount])):
        work -= int(blist[bCount])
        bCount += 1
    maxCount = max(maxCount, acount-num+bCount)




print(maxCount)


# -*- coding: utf-8 -*-
n, m, k = map(int, input().split())

alist = input().split()
blist = input().split()

work = k
acount = 0
while (acount < n) and (work >= int(alist[acount])):
    work -= int(alist[acount])
    acount += 1

bCount = 0
work2 = work
while (bCount < m) and (work2 >= int(blist[bCount])):
        work2 -= int(blist[bCount])
        bCount += 1


maxCount = acount + bCount
bCount = 0
for num in range(0, acount):
    work += int(alist[acount-num-1])

    while (bCount < m) and (work >= int(blist[bCount])):
        work -= int(blist[bCount])
        bCount += 1
    maxCount = max(maxCount, acount-num-1+bCount)


print(maxCount)

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

for i in range(n-1):
    a[i+1] = a[i] + a[i+1]
a.insert(0, 0)
for i in range(m-1):
    b[i+1] = b[i] + b[i+1]
b.insert(0, 0)
print(a)
print(b)
x = 0
for i in range(n+1):
    for j in range(m+1):
        if b[m-j] > k-a[i]:
            pass
        else:
            jmax = m-j
            if jmax + i > x:
              x = jmax + i
print(x)

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

for i in range(n-1):
    a[i+1] = a[i] + a[i+1]
a.insert(0, 0)
for i in range(m-1):
    b[i+1] = b[i] + b[i+1]
b.insert(0, 0)

x = 0
jmax = m
for i in range(n+1):
    for j in range(jmax, -1, -1):
        if b[j] > k-a[i]:
            pass
        else:
            jmax = j
            if jmax + i > x:
                x = jmax + i
            break
print(x)

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
m = M
for n in range(N + 1):
  while True:
    time = A[n] + B[m]
    if time <= K:
      ans = max(ans, n + m)
      break
    else:
      j -= 1
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 n in range(N + 1):
  while True:
    time = A[n] + B[j]
    if time > K:
      j -= 1
    else:
      ans = max(ans, n + j)
      break
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 n in range(N + 1):
  while B[j] > K - A[n]:
      j -= 1
  ans = max(ans, n + 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 n in range(N + 1):
  if A[n] > K:
    break
  while B[j] > K - A[n]:
      j -= 1
  ans = max(ans, n + j)
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()))

from itertools import accumulate
a = list(accumulate(a))
b = list(accumulate(b))

from collections import deque
u = deque([0])
a.append(0)

import bisect
for i in range(n+1):
    if k-a[i]>=0:
        index = bisect.bisect_left(b,k-a[i])
        u.append(index+i)
    else:
        break
print(max(u))


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

from itertools import accumulate
a = list(accumulate(a))
b = list(accumulate(b))

from collections import deque
u = deque([0])
a.insert(0,0)

import bisect
for i in range(n+1):
    if k-a[i]>=0:
        index = bisect.bisect_right(b,k-a[i])
        u.append(index+i)
    else:
        break
print(max(u))

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.append(2*10**10)
B.append(2*10**10)
A.append(2*10**10)
B.append(2*10**10)
 
ans = 0
t = 0
ia, ib = 0, 0
while t < K and (ia < N or ib < M):
    if A[ia] + A[ia+1] <= B[ib] + B[ib+1]:
        if t + A[ia] <= K:
            t += A[ia]
            ans += 1
            ia += 1
        else: break
    else:
        if t + B[ib] <= K:
            t += B[ib]
            ans += 1
            ib += 1
        else: break
    print(t, ia, ib, ans)
 
print(ans)

from bisect import bisect_left
N, M ,K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
SA =[A[0]]
for i in A[1:]:
    SA.append(SA[-1] + i)
SB =[0]
for i in B:
    SB.append(SB[-1] + i)

i = bisect_left(SA, K)
SA = SA[: i+1]
SA.append(2*10**9)
i = bisect_left(SB, K)
SB = SB[: i+1]
if SB[-1] > K: SB.pop()

i, ii = 0, 0
j = len(SB) - 1
ans = [j]
while j >= 0:
    diff = K - SB[j]
    jdg = False
    for ii in range(i, len(SA)):
        if SA[ii] > diff:
            jdg = True
            break
    i = ii
    ans.append(i + j)
    j -= 1
print(max(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()))

aa = [0]*(N+1)
for i in range(1, N+1):
    aa[i] = aa[i-1]+A[i-1]

bb = [0]*(M+1)
for i in range(1, M+1):
    bb[i] = bb[i-1]+B[i-1]

ans = 0
for i in range(N+1):
    tmp_K = K-aa[i]
    if tmp_K == 0:
        ans = max(ans, i)
    elif tmp_K < 0:
        continue

    if tmp_K <= bb[-1]:
        ans = max(ans, i+M)
    mn = 0
    mx = M
    while True:
        if mn == mx:
            if tmp_K >= bb[mn]:
                ans = max(ans, i+mn)
            break

        mid = (mn+mx//2)
        if bb[mid] <= tmp_K:
            if mn == mid:
                mn = mid+1
            else:
                mn = mid
        else:
            if mx == mid:
                mx = mid-1
            else:
                mx = mid
print(ans)


import itertools
import bisect

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

aa = [0] + list(itertools.accumulate(A))
bb = [0] + list(itertools.accumulate(B))

ans = bisect.bisect_left(aa, K)-1
ans = max(ans, bisect.bisect_left(bb, K)-1)

for i in reversed(range(N+1)):
    tmp_K = K-aa[i]
    if tmp_K == 0:
        ans = max(ans, i)
    elif tmp_K < 0:
        continue

    if i + M <= ans:
        continue

    if tmp_K >= bb[-1]:
        ans = max(ans, i+M)
        continue

    ans = max(ans, bisect.bisect_left(bb, tmp_K)-1+i)
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):
import sys
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]

mod = 10 ** 9 + 7

N, M, K = LS()
desk = LSR(2)
a, b = [0], [0]

# a = [0, 0 + A1, 0 + A1 + A2, ....]
# b = [0, 0 + B1, 0 + B1 + B2, ....]
for i in range(N):
    a.append(a[i] + desk[0][i])
for j in range(M):
    b.append(b[j] + desk[1][j])



ans, j = 0, M 

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

print(ans)

import sys
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]

mod = 10 ** 9 + 7

N, M, K = LI()
desk = LIR(2)
a, b = [0], [0]

# a = [0, 0 + A1, 0 + A1 + A2, ....]
# b = [0, 0 + B1, 0 + B1 + B2, ....]
for i in range(N):
    a.append(a[i] + desk[0][i])
for j in range(M):
    b.append(b[j] + desk[1][j])



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):
from itertools import accumulate
from bisect import bisect_left
 
n,m,k=map(int,input().split())
a=list(accumulate([0]+list(map(int,input().split()))))
b=list(accumulate([0]+list(map(int,input().split()))))
mx=0
for i in range(n+1):
  idx=bisect_left(b,max(k-a[i],0))
  mx=max(mx,i+idx)
print(mx)
  

from itertools import accumulate
from bisect import bisect_left
 
n,m,k=map(int,input().split())
a=list(accumulate([0]+list(map(int,input().split()))))
b=list(accumulate([0]+list(map(int,input().split()))))
#print(b)
mx=0
for i in range(n+1):
  if a[i]>k:continue
  #print('a[i];'+str(a[i]))
  idx=min(bisect_left(b,k-a[i]),m)
  #print(idx)
  if b[idx]>k-a[i]:idx-=1
  if a[i]+b[idx]>k:continue
  mx=max(mx,i+idx)
print(mx)
  

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

for i in range(1, n):
    a[i] += a[i - 1]

for i in range(1, m):
    b[i] += b[i - 1]

ptr = 0
ans = 0

for i in range(n):
    if a[i] > k:
        break
    while ptr < m:
        if a[i] + b[ptr] >= k:
            break
        ptr += 1
    print(i, ptr)
    ans = max(ans, i + min(ptr, m) + 1)

print(ans)


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])

ptr = m
ans = 0

for i in range(n + 1):
    if a[i] > k:
        break
    while a[i] + b[ptr] > k:
        ptr -= 1
    ans = max(ans, i + ptr)

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


def Cum(X):
    temp = 0
    Cum = [0]*len(X)
    for i in range(len(X)):
        temp += X[i]
        Cum[i] += temp
    return Cum

a = Cum(A)
a.insert(0,0)
b = Cum(B)
b.insert(0,0)

na = 0
for i in range(N+1):
    if i == N and a[i]<=K:
        na = N
    elif a[i]<=K and a[i+1]>K:
        na = i

ans = na
temp = K-a[na]
nb = 0
for i in range(na,-1,-1):
    for j in range(nb,M+1):
        if j == M and b[i] <= temp:
            nb = M
        elif b[j]<=temp and b[j+1]>temp:
            nb = j
        ans = max(ans,i+nb)
print(ans)

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


def Cum(X):
    temp = 0
    Cum = [0]*len(X)
    for i in range(len(X)):
        temp += X[i]
        Cum[i] += temp
    return Cum

a = Cum(A)
a.insert(0,0)
b = Cum(B)
b.insert(0,0)

na = 0
for i in range(N+1):
    if i == N and a[i]<=K:
        na = N
    elif a[i]<=K and a[i+1]>K:
        na = i

ans = na

nb = 0
for i in range(na,-1,-1):
    temp = K-a[i]
    for j in range(nb,M+1):
        if j == M and b[j] <= temp:
            nb = M
            ans = max(ans,i+nb)
        elif b[j]<=temp and b[j+1]>temp:
            nb = j
            ans = max(ans,i+nb)
            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):
def dfs(a, b, k):
    nonlocal cnt
    seen[a][b] = True
    na = a + 1
    nb = b + 1
    if na <= N and seen[na][b] is False and k >= book_a[na]:
        k -= book_a[na]
        cnt = max(cnt, na + b)
        dfs(na, b, k)
    if nb <= M and seen[a][nb] is False and k >= book_b[nb]:
        k -= book_b[nb]
        cnt = max(cnt, a + nb)
        dfs(a, nb, k)
        
N, M, k = map(int, input().split())
book_a = [int(x) for x in input().split()]
book_b = [int(x) for x in input().split()]
book_a.insert(0, 0)
book_b.insert(0, 0)
cnt = 0
seen = [[False] * (M + 1) for _ in range(N + 1)]
dfs(0, 0, k)
print(cnt)

def resolve():
    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)



if __name__ == "__main__":
    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):
from collections import deque
n,m,k=map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

amax = 0
time = 0
for a in A:
  if time + a > k: break
  time += a
  amax += 1
bmax,time = 0,0
for b in B:
  if time + b > k: break
  time += b
  bmax += 1
if amax == 0:
  print(bmax)
  exit()
if bmax == 0:
  print(amax)
  exit()
v = max(amax,bmax)
ans = v
#print(amax,bmax)
for i in range(v+1,k+1):
  ok = False
  for j in range(i+1):
    if j>n or i-j > m: continue
    t = sum(A[:i])+sum(B[:(i-j)])
    if t <= k:
      ans = i
      ok = True
      break
  if ok == False:
    print(ans)
    exit()
print(ans)

from collections import deque
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)

from itertools import accumulate
from bisect import bisect
n,m,k=map(int,input().split())
A=list(map(int,input().split()))
A=list(accumulate(A,initial=0))
B=list(map(int,input().split()))
B=list(accumulate(B))

ans = 0
for i,a in enumerate(A):
  if a > k: break
  ans = max(ans,i + bisect(B,k-a))
print(ans)

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 = list(map(int,input().split()))
b = list(map(int,input().split()))
na = []
c = 0
for booka in a:
  c += booka
  na.append(c)
nb = []
d = 0
for bookb in b:
  d += bookb
  nb.append(d)
maxa = 0
for i in range(n):
  for j in range(maxa-i,m):
    if na[i] + nb[j] <= k:
      maxa = max(maxa,i+j+2)
print(maxa)

n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
na,nb = [0],[0]
for i in range(n):
  na.append(na[i]+a[i])
for j in range(m):
  nb.append(nb[j]+b[j])
ans = 0
l = m
for i in range(n+1):
  if na[i] > k:
    break
  while nb[l] > k - na[i]:
    l -= 1
  ans = max(ans,i+l)
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())
arr0 = list(map(int,input().split()))
arr1 = list(map(int,input().split()))
acc0 = []

for i in range(n):
  acc0.append(acc0[-1] + arr0[i])
acc1 = []
for i in range(m):
  acc1.append(acc1[-1] + arr1[i])
ans = 0
j = m
for i in range(n+1):
  if acc0[i] > k:
    break
  while acc1[j] > k - acc0[i] and j > 0:
    j -= 1
  ans = max(ans, i + j)

print(ans)


n,m,k = map(int,input().split())
arr0 = list(map(int,input().split()))
arr1 = list(map(int,input().split()))
acc0 = [0]

for i in range(n):
  acc0.append(acc0[-1] + arr0[i])
acc1 = [0]
for i in range(m):
  acc1.append(acc1[-1] + arr1[i])
ans = 0
j = m
for i in range(n+1):
  if acc0[i] > k:
    break
  while acc1[j] > k - acc0[i] and j > 0:
    j -= 1
  ans = max(i + j)

print(ans)


n,m,k = map(int,input().split())
arr0 = list(map(int,input().split()))
arr1 = list(map(int,input().split()))
acc0 = [0]

for i in range(n):
  acc0.append(acc0[-1] + arr0[i])
acc1 = [0]
for i in range(m):
  acc1.append(acc1[-1] + arr1[i])
ans = 0
j = m
for i in range(n+1):
  if acc0[i] > k:
    break
  while acc1[j] > k - acc0[i] and j > 0:
    j -= 1
  ans = max(ans, i + j)

print(ans)

Verdicts: 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())
al=[int(i) for i in input().split()]
bl=[int(i) for i in input().split()]
for i in range(1,n):
    al[i]+=al[i-1]
for i in range(1,m):
    bl[i]+=bl[i-1]
ans=0
j=m-1
for i in in range(n):
    if al[i]>k:
        break
    while bl[j]>al[i]-k:
        j-=1
    ans=max(ans,i+j)
print(ans)


n,m,k=map(int,input().split())
al=[int(i) for i in input().split()]
bl=[int(i) for i in input().split()]
for i in range(1,n):
    al[i]+=al[i-1]
for i in range(1,m):
    bl[i]+=bl[i-1]
ans=0
j=m
for i in in range(n):
    if al[i]>k:
        break
    while bl[j]>al[i]-k:
        j-=1
    ans=max(ans,i+j)
print(ans)


n,m,k=map(int,input().split())
al=[int(i) for i in input().split()]
bl=[int(i) for i in input().split()]
aa,bb=[0],[0]
for i in range(n):
    aa.append(aa[i]+al[i])
for i in range(m):
    bb.append(bb[i]+bl[i])
ans=0
j=m
for i in range(n+1):
    if aa[i]>k:
        break
    while bb[j]>k-aa[i]:
        j-=1
    ans=max(ans,i+j)
print(ans)


Verdicts: 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 math
import sys

sys.setrecursionlimit(10 ** 9)


def binary_research(start, end,function):
    if start == end:
        return start
    middle = math.ceil((start + end) / 2)
    if function(middle, k, a_sum, b_sum):
        start = middle
    else:
        end = middle - 1
    return binary_research(start, end, function)


# ==================================================-

n, m, k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
a_sum = [0]
b_sum = [0]
for book in a:
    a_sum.append(a_sum[-1] + book)
for book in b:
    b_sum.append(b_sum[-1] + book)


def can_read(num, k, a_sum, b_sum):
    min_read_time = 1000000000000
    sentou=
    for i in range(max(0, num - m), min(num+1,n+1)):
        a_num = i
        b_num = num - i
        min_read_time = min(min_read_time, a_sum[a_num] + b_sum[b_num])
    if min_read_time <= k:
        return True
    return False


start = 0
end = n + m

print(binary_research(start, end, can_read))

# ==================================================-



import math
import sys

sys.setrecursionlimit(10 ** 9)


def binary_research(start, end,function):
    if start == end:
        return start
    middle = math.ceil((start + end) / 2)
    if function(middle, k, a_sum, b_sum):
        start = middle
    else:
        end = middle - 1
    return binary_research(start, end, function)


# ==================================================-

n, m, k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
a_sum = [0]
b_sum = [0]
for book in a:
    a_sum.append(a_sum[-1] + book)
for book in b:
    b_sum.append(b_sum[-1] + book)


def can_read(num, k, a_sum, b_sum):
    min_read_time = 1000000000000
    for i in range(max(0, num - m), min(num+1,n+1)):
        a_num = i
        b_num = num - i
        min_read_time = min(min_read_time, a_sum[a_num] + b_sum[b_num])
    if min_read_time <= k:
        return True
    return False


start = 0
end = n + m

print(binary_research(start, end, can_read))

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

t = sum(A)
i = N
ans = 0

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

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

t = sum(A)
i = N
ans = 0

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

Verdicts: Wrong Answer

Accepted