Problem:


Score : 300 points

Problem Statement

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.

Constraints

1 \leq N, M \leq 200000

1 \leq K \leq 10^9

1 \leq A_i, B_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M K
A_1 A_2 \ldots A_N
B_1 B_2 \ldots B_M

Output

Print an integer representing the maximum number of books that can be read.

Sample Input 1

3 4 240
60 90 120
80 150 80 150

Sample Output 1

3

In this case, it takes us 60, 90, 120 minutes to read the 1-st, 2-nd, 3-rd books from the top on Desk A, and 80, 150, 80, 150 minutes to read the 1-st, 2-nd, 3-rd, 4-th books from the top on Desk B, respectively.

We can read three books in 230 minutes, as shown below, and this is the maximum number of books we can read within 240 minutes.

Read the topmost book on Desk A in 60 minutes, and remove that book from the desk.

Read the topmost book on Desk B in 80 minutes, and remove that book from the desk.

Read the topmost book on Desk A in 90 minutes, and remove that book from the desk.

Sample Input 2

3 4 730
60 90 120
80 150 80 150

Sample Output 2

7

Sample Input 3

5 4 1
1000000000 1000000000 1000000000 1000000000 1000000000
1000000000 1000000000 1000000000 1000000000

Sample Output 3

0

Watch out for integer overflows.



Sample input:
3 4 240
60 90 120
80 150 80 150


Sample output:
3

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations

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

    cumsumA = [0] + list(accumulate(A))
    cumsumB = [0] + list(accumulate(B))

    res = 0

    for i in range(N+1):
        if i == 0:
            for j in range(M, -1, -1):
                if cumsumB[j] <= K:
                    max_j = j
                    break
        else:
            for j in range(max_j, -1, -1):
                time = cumsumA[i] + cumsumB[j]
                if  time <= K:
                    max_j = j
                    if res < i + j:
                        res = i + j
                    break
    
    print(res)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
times_a = list(map(int, input().split()))
times_b = list(map(int, input().split()))
read_time = 0
read_time_a = [0]
read_time_b = [0]
for i in range(N):
    read_time_a.append(read_time_a[i]+times_a[i])
for i in range(M):
    read_time_b.append(read_time_b[i]+times_b[i])

ans = 0
for a_count in range(N+1):
    a_read_time = read_time_a[a_count]
    max_b_count = 0
    r = len(read_time_b)
    # 消化時間の配列はソートされている状態だから二分探索
    # 計算量をlog(M)に削減
    while max_b_count + 1 < r:
        c = (max_b_count + r) // 2
        # bがインデックスcで時間がaの時間+bの時間でK以下ならmax_b_countを二分探索の開始位置に更新する。
        if a_read_time + read_time_b[c] <= K:
            max_b_count = c
        # 超えちゃったら二分探索の前方に探索領域の終端を絞る
        else:
            r = c
    # 積読消化時間がKより小さく、a_count + max_b_countの最大数が最大になるものをansに代入し続ける
    # if read_time_a[a_count] + read_time_b[max_b_count] <= K:
    ans = max(ans, a_count + max_b_count)
print(ans)

Submission status: Wrong Answer

Solution code:
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=max(bisect_left(b,k-a[i])-1, 0)
  #print(idx)
  if a[i]+b[idx]>k:continue
  mx=max(mx,i+idx)
print(mx)

Submission status: Wrong Answer

Solution code:
from bisect import *
n, m, k = map(int, input().split())
A = [0]
for x in map(int, input().split()):
    if A[-1]+x <= k: A.append(A[-1]+x)
B = [0]
for x in map(int, input().split()):
    if B[-1]+x <= k: B.append(B[-1]+x)
ans = 0
for i in range(len(A)):
    j = bisect_right(B, k-A[i]) - 1
    # if k >= A[i] + B[j]:
        # ans = max(ans, i+j)
    ans = max(ans, i+j)

# print(k)
# print(A)
# print(B)
print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import *
n, m, k = map(int, input().split())
A = [0]
for x in map(int, input().split()):
    if A[-1]+x <= k: A.append(A[-1]+x)
B = [0]
for x in map(int, input().split()):
    if B[-1]+x <= k: B.append(B[-1]+x)
ans = 0
na = len(A)
# nb = len(B)
# for i in range(na):
for i in range(len(A)):
    j = bisect_right(B, k-A[i]) - 1
    if k >= A[i] + B[j]:
        ans = max(ans, i+j)
    # print('i',i,'a',a,'残',k-a,'j',j,'b',B[j],'a+b',a+B[j],'i+j',i+j)
    # print('i',i,'a',a,'残',k-a,'j',j,'b',B[j],'a+b',a+b,'i+j',i+j, '(a+b>k)',(a+b>k))
# print(k)
# print(A)
# print(B)
print(ans)

Submission status: Wrong Answer

Solution code:
# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


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

    sumA = [0] * (N+1)
    sumB = [0] * (M+1)

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

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

    for i in range(M,-1,-1):
        if sumB[i] <= K:
            endB = i
            break

    for i in range(N,-1,-1):
        if sumA[i] <= K:
            endA = i
            break

    res = 0

    for i in range(1,endA+1):
        for j in range(endB,-1,-1):
            if sumA[i] + sumB[j] <= K:
                endB = j
                res = max(res,i+j)
                break

    print(res)



main()

Submission status: Wrong Answer

Solution code:
import sys
import math
import collections

def set_debug(debug_mode=False):
    if debug_mode:
        fin = open('input.txt', 'r')
        sys.stdin = fin


def int_input():
    return list(map(int, input().split()))


if __name__ == '__main__':
    # set_debug(True)

    # t = int(input())
    t = 1

    for ti in range(1, t + 1):
        n = int_input()
        k = n[-1]
        A = int_input()
        B = int_input()

        a = 0
        b = 0

        res = 0

        while a < len(A) and b < len(B):
            if A[a] > k and B[b] > k:
                break
            else:
                if A[a] <= B[b]:
                    k -= A[a]
                    a += 1
                else:
                    k -= B[b]
                    b += 1
                res += 1

        while a < len(A):
            if A[a] <= k:
                res += 1
                k -= A[a]
                a += 1
            else:
                break

        while b < len(B):
            if B[b] <= k:
                res += 1
                k -= B[b]
                b += 1
            else:
                break


        print(res)

Submission status: Wrong Answer

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

max_n = 0

for i in range(n):
    for j in range(m):
        if sum(a[:i])+sum(b[:j]) > k:
            max_n =  max(i+j-1 ,max_n)
            print(i,j,sum(a[:i])+sum(b[:j]))
            break
            
print(max_n)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
arr1=list(map(int,input().split()))
arr2=list(map(int,input().split()))
arr1.reverse()
arr2.reverse()
ans=0
c=0
while(c<k):
    if len(arr1)>0 and len(arr2)>0:
        if arr1[-1]<arr2[-1]:
            c+=arr1[-1]
            arr1.pop()
        else:
            c+=arr2[-1]
            arr2.pop()
    else:
        if len(arr1)>0:
            c+=arr1[-1]
            arr1.pop()
        if len(arr2)>0:
            c+=arr2[-1]
            arr2.pop()
    ans+=1
    if len(arr1)==len(arr2)==0:
        break
if c<=k:
    print(ans)
else:
    print(ans-1)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
import bisect
n, m, k = map(int,input().split())
a_lst = [0] + list(accumulate(list(map(int,input().split()))))
b_lst = list(accumulate(list(map(int,input().split()))))

ans = 0
for i in range(n+1):
    cnt = i
    num = k - a_lst[i]
    if num < 0:
        continue
    b_yomeru = bisect.bisect_left(b_lst,num)
    cnt += b_yomeru
    if ans < cnt:
        ans = cnt

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque


def main():
    n, m, k = list(map(int, input().split()))
    a = deque(list(map(int, input().split())))
    b = deque(list(map(int, input().split())))

    c = 0
    while True:
        if len(a) == 0 and len(b) == 0:
            break
        elif len(b) == 0:
            k -= a.popleft()
        elif len(a) == 0:
            k -= b.popleft()
        elif a[0] < b[0]:
            k -= a.popleft()
        else:
            k -= b.popleft()

        if k < 0:
            break
        c += 1

    print(c)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
c=0
k=M
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 K-B[j]>=0:
        if c<j+1:
          c=j+1
        break
    break
  else:
    for j in reversed(range(k)):
      if d>=B[j]:
        if c<i+j+2:
          c=i+j+2
        k=j+1
        break
    if d<B[0]:
      if c<i+1:
        c=i+1
      k=0

print(c)

Submission status: Wrong Answer

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

a_sum = [0]
b_sum = [0]
cnt = 0
best_b = m

for i in a:
    a_sum.append(i + a_sum[-1])

for i in b:
    b_sum.append(i + b_sum[-1])

for a_idx in range(n + 1):
    for b_idx in reversed(range(best_b + 1)):
        if b_sum[b_idx] + a_sum[a_idx] <= k:
            cnt = b_idx + a_idx
            best_b = b_idx
            break

print(cnt)

Submission status: Wrong Answer

Solution code:
def INPUT():return list(int(i) for i in input().split())
n,m,k=INPUT()
A=INPUT()
B=INPUT()
Sa=[0]*(n+1)
Sb=[0]*(m+1)
for i in range(1,n+1):
    Sa[i]+=Sa[i-1]+A[i-1]
for j in range(1,m+1):
    Sb[j]+=Sb[j-1]+B[j-1]
for i in range(n+1):
    if Sa[i]>k:
        break
    else:
        x=i
for j in range(m+1):
    if Sb[j]>k:
        break
    else:
        y=j
sum=Sa[x]+Sb[y]
# print(sum)
# print(Sa)
# print(Sb)
ans=x+y
while(sum>k and y>0 and x>0):
    if A[x-1]<B[y-1]:
        sum-=B[y-1]
        y-=1
        ans-=1
    else:
        sum-=A[x-1]
        x-=1
        ans-=1
    #print(sum)
if sum>k:
    if x==0 and y==0:
        ans=m+n
    elif x==0 and y!=0:
        while(y>0 and sum>k):
            sum-=B[y-1]
            y-=1
            ans-=1
    else:
        while(x>0 and sum>k):
            sum-=A[x-1]
            x-=1
            ans-=1



print(ans)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
arr1=list(map(int,input().split()))
arr2=list(map(int,input().split()))
arr1.reverse()
arr2.reverse()
ans=0
c=0
while(c<k):
    if len(arr1)>0 and len(arr2)>0:
        if arr1[-1]<arr2[-1]:
            c+=arr1[-1]
            arr1.pop()
        else:
            c+=arr2[-1]
            arr2.pop()
    else:
        if len(arr1)>0:
            c+=arr1[-1]
            arr1.pop()
        if len(arr2)>0:
            c+=arr2[-1]
            arr2.pop()
    ans+=1
    if len(arr1)==len(arr2)==0:
        break
if c==k:
    print(ans)
else:
    print(ans-1)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
A.append(9999999999)
B.append(9999999999)
a,b = [0],[0]
for i in range(len(A)):
    a.append(a[i]+A[i])
for i in range(len(B)):
    b.append(b[i]+B[i])
i=1
j=1
time = 0
while time < k:
    if a[i] <= b[j] and a[i]-a[i-1]+time <= k:
        time +=(a[i]-a[i-1])
        i+=1
    elif a[i] >= b[j] and b[j]-b[j-1]+time <= k:
        time+=(b[j]-b[j-1])
        j+=1
    else:
        break
print(i+j-2)

Submission status: Wrong Answer

Solution code:
import logging

logging.basicConfig(level=logging.INFO)
logging.info('info')


def main():
    N, M, K = map(int, input().split())
    A_list = list(map(int, input().split()))
    B_list = list(map(int, input().split()))
    logging.info("hello")

    a = [0]
    b = [0]

    for i in range(N):
        a.append(a[i] + A_list[i])

    for i in range(M):
        b.append(b[i] + B_list[i])

    ans = 0
    #j = M
    for i in range(N + 1):
        if a[i] > K:
            break
        for j in range(M):
            if b[M - j] > K - a[i]:
                continue
            else:
                break

        ans = max(ans, i + M - j + 1)

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import logging

logging.basicConfig(level=logging.INFO)
logging.info('info')


def main():
    N, M, K = map(int, input().split())
    A_list = list(map(int, input().split()))
    B_list = list(map(int, input().split()))
    logging.info("hello")

    a = [0]
    b = [0]

    for i in range(N):
        a.append(a[i] + A_list[i])

    for i in range(M):
        b.append(b[i] + B_list[i])

    ans = 0
    #j = M
    for i in range(N + 1):
        if a[i] > K:
            break
        for j in range(M):
            if b[M - j] > K - a[i]:
                continue
            else:
                break

        ans = max(ans, i + M - j)

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
arr1=list(map(int,input().split()))
arr2=list(map(int,input().split()))
arr1.reverse()
arr2.reverse()
ans=0
c=0
while(len(arr1)>0 or len(arr2)>0):
    if len(arr1)>0 and len(arr2)>0:
        if arr1[-1]<arr2[-1]:
            c+=arr1[-1]
            arr1.pop()
        else:
            c+=arr2[-1]
            arr2.pop()
    else:
        if len(arr1)>0:
            c+=arr1[-1]
            arr1.pop()
        if len(arr2)>0:
            c+=arr2[-1]
            arr2.pop()
    ans+=1
    if c>=k:
        break
if c==k:
    print(ans)
else:
    print(ans-1)

Submission status: Wrong Answer

Solution code:
def main():
    n, m, k = list(map(int, input().split()))
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))

    c = 0
    while True:
        if len(a) == 0 and len(b) == 0:
            break
        elif len(b) == 0:
            k -= a.pop(0)
        elif len(a) == 0:
            k -= b.pop(0)
        elif a[0] < b[0]:
            k -= a.pop(0)
        else:
            k -= b.pop(0)

        if k < 0:
            break
        c += 1

    print(c)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
import math 
from collections import deque

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import *
n, m, k = map(int, input().split())
A = [0]
for x in map(int, input().split()):
    if A[-1]+x <= k: A.append(A[-1]+x)
B = [0]
for x in map(int, input().split()):
    if B[-1]+x <= k: B.append(B[-1]+x)

ans = 0
na = len(A)
nb = len(B)
for i in range(na):
    a = A[i]
    j = bisect_right(B, k-a) - 1
    b = B[j]
    ans = max(ans, i+j)
    # print('i',i,'a',a,'残',k-a,'j',j,'b',b,'a+b',a+b,'i+j',i+j, '(a+b>k)',(a+b>k))


# print(k)
# print(A)
# print(B)

print(ans)

Submission status: Wrong Answer

Solution code:
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
c=0
k=M
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 K-B[j]>=0:
        if c<j+1:
          c=j+1
        break
    break
  else:
    for j in reversed(range(k)):
      if d>=B[j]:
        if c<i+j+2:
          c=i+j+2
        k=j+1
        break
    if d<B[0]:
      if c<i+1:
        c=i+1
      k=0

print(c)

Submission status: Wrong Answer

Solution code:
import logging

logging.basicConfig(level=logging.INFO)
logging.info('info')


def main():
    N, M, K = map(int, input().split())
    A_list = list(map(int, input().split()))
    B_list = list(map(int, input().split()))
    logging.info("hello")

    a = [0]
    b = [0]

    for i in range(N):
        a.append(a[i] + A_list[i])

    for i in range(M):
        b.append(b[i] + B_list[i])

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

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from bisect import *
n, m, k = map(int, input().split())
A = [0]
for x in map(int, input().split()):
    if A[-1]+x <= k: A.append(A[-1]+x)
B = [0]
for x in map(int, input().split()):
    if B[-1]+x <= k: B.append(B[-1]+x)

ans = 0
na = len(A)
nb = len(B)
for i in range(na):
    a = A[i]
    j = bisect_right(B, k-a) - 1
    b = B[j]
    ans = max(ans, i+j - (a+b>k))
    # print('i',i,'a',a,'残',k-a,'j',j,'b',b,'a+b',a+b,'i+j',i+j, '(a+b>k)',(a+b>k))


# print(k)
# print(A)
# print(B)

print(ans)

Submission status: Wrong Answer

Solution code:
import logging

logging.basicConfig(level=logging.INFO)
logging.info('info')


def main():
    N, M, K = map(int, input().split())
    A_list = list(map(int, input().split()))
    B_list = list(map(int, input().split()))
    logging.info("hello")

    a = [0]
    b = [0]

    for i in range(N):
        a.append(a[i] + A_list[i])

    for i in range(M):
        b.append(b[i] + B_list[i])

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

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np
n, m, k = [int(n) for n in input().split()]
A = [int(n) for n in input().split()]
B = [int(n) for n in input().split()]

A = [a for a in np.cumsum([0] + A) if a <= k]
B = [b for b in np.cumsum([0] + B) if b <= k]
B, A = sorted((A, B), key=len)
for i, a in enumerate(A[::-1]):
    for j, b in enumerate(B[::-1]):
        if a + b <= k:
            n_read = len(A) + len(B) - i  - j - 2
            break
    if a + b <= k:
        break
print(n_read)

Submission status: Wrong Answer

Solution code:
def main():
    n, m, k = list(map(int, input().split()))
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))

    c = 0
    while k >= 0:
        c += 1
        if len(a) == 0 and len(b) == 0:
            break
        elif len(b) == 0:
            k -= a.pop(0)
        elif len(a) == 0:
            k -= b.pop(0)
        elif a[0] < b[0]:
            k -= a.pop(0)
        else:
            k -= b.pop(0)

    print(c - 1)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import itertools
import bisect

n,m,k=map(int,input().split())
a=[0]+list(map(int,input().split()))
b=list(map(int,input().split()))
aa=list(itertools.accumulate(a))
bb=list(itertools.accumulate(b))
r=0
for i,ax in enumerate(aa):
    bis=bisect.bisect_right(bb,k-ax)
    r=max(r,i+bis)
    if bis==0:print(r);exit()
print(r)

Submission status: Wrong Answer

Solution code:
from bisect import *
n, m, k = map(int, input().split())
A = [0]
for x in map(int, input().split()):
    if A[-1]+x <= k: A.append(A[-1]+x)
B = [0]
for x in map(int, input().split()):
    if B[-1]+x <= k: B.append(B[-1]+x)

ans = 0
na = len(A)
nb = len(B)
for i in range(na):
    a = A[i]
    j = min(nb-1, bisect_right(B, k-a))
    b = B[j]
    ans = max(ans, i+j - (a+b>k))
    # print('i',i,'a',a,'残',k-a,'j',j,'b',b,'a+b',a+b,'i+j',i+j, '(a+b>k)',(a+b>k))

for i in range(nb):
    b = B[i]
    j = min(na-1, bisect_right(A, k-b))
    a = A[j]
    ans = max(ans, i+j - (a+b>k))
    # print('i',i,'a',a,'残',k-a,'j',j,'b',b,'a+b',a+b,'i+j',i+j, '(a+b>k)',(a+b>k))

# print(k)
# print(A)
# print(B)

print(ans)

Submission status: Wrong Answer

Solution code:
import logging

logging.basicConfig(level=logging.INFO)
logging.info('info')


def main():
    N, M, K = map(int, input().split())
    A_list = list(map(int, input().split()))
    B_list = list(map(int, input().split()))
    logging.info("hello")

    a = [0]
    b = [0]

    for i in range(N):
        a.append(a[i] + A_list[i])

    for i in range(M):
        b.append(b[i] + B_list[i])

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

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import itertools
import bisect

n,m,k=map(int,input().split())
a=[0]+list(map(int,input().split()))
b=list(map(int,input().split()))
aa=list(itertools.accumulate(a))
bb=list(itertools.accumulate(b))
r=0
for i,ax in enumerate(aa):
    bis=bisect.bisect_right(bb,k-ax)
    if bis==0:print(r);exit()
    r=max(r,i+bis)
print(r)

Submission status: Wrong Answer

Solution code:
import itertools

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

sumA = list(itertools.accumulate(A))
sumB = list(itertools.accumulate(B))
j=M-1
while K<sumB[j] and j>0:
    j-=1
ans=j
for i in range(N):
    if sumA[i]>K:
        break
    while K<sumA[i]+sumB[j] and j>0:
        j-=1
    ans=max(ans,i+j+2)
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools

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

sumA = list(itertools.accumulate(A))
sumB = list(itertools.accumulate(B))
j=M-1
while K<sumB[j] and j>0:
    j-=1
ans=j
for i in range(N):
    if sumA[i]>K:
        break
    while K<sumA[i]+sumB[j] and j>=0:
        j-=1
    ans=max(ans,i+j+2)
print(ans)

Submission status: Wrong Answer

Solution code:
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
c=0
k=M
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(k)):
      if d>=B[j]:
        if c<i+j+2:
          c=i+j+2
        k=j+1
        break
    if d<B[0]:
      if c<i+1:
        c=i+1
      k=0
  else:
    for j in reversed(range(M)):
      if K-B[j]>=0:
        if c<j+1:
          c=j+1
        break
    break
print(c)

Submission status: Wrong Answer

Solution code:
from itertools import *
f=lambda:map(int,input().split())
g=lambda:[0]+[*accumulate(f())]
n,m,k=f()
A,B=g(),g()
a,j=0,m
for i in range(n+1):
  while j and (b:=B[j]>k-A[i]): j-=1
  if b^1: a=max(a,i+j)
print(a)

Submission status: Wrong Answer

Solution code:
import itertools

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

sumA = list(itertools.accumulate(A))
sumB = list(itertools.accumulate(B))
j=M-1
while K<sumB[j] and j>0:
    j-=1
ans=j
for i in range(1,N):
    if sumA[i]>K:
        break
    while K<sumA[i]+sumB[j] and j>=0:
        j-=1
    ans=max(ans,i+j+2)
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools

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

sumA = list(itertools.accumulate(A))
sumB = list(itertools.accumulate(B))
j=M-1
while K<sumB[j] and j>0:
    j-=1
ans=j
for i in range(1,N):
    if sumA[i]>K:
        break
    while K<sumA[i]+sumB[j] and j>0:
        j-=1
    ans=max(ans,i+j+2)
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
n, m, k = [int(n) for n in input().split()]
A = [int(n) for n in input().split()]
B = [int(n) for n in input().split()]

A = [a for a in np.cumsum([0] + A) if a <= k]
B = [b for b in np.cumsum([0] + B) if b <= k]
n_read = 0
for i, a in enumerate(A[::-1]):
    for j, b in enumerate(B[::-1]):
        if a + b <= k:
            n_read = len(A) + len(B) - i  - j - 2
            break
    if a + b <= k:
        break
print(n_read)

Submission status: Wrong Answer

Solution code:
from sys import stdin

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

A2 = []
B2 = []
temp = 0
for a in A:
    temp += a
    A2.append(temp)
temp = 0
for b in B:
    temp += b
    B2.append(temp)

kouho = []
for i,value in enumerate(A2):
    if value > K:
        break
    for i2,value2 in enumerate(B2[::-1]):
        if value + value2 <= K:
            kouho.append(i+1+len(B2)-i2)

if kouho == []:
    print(0)
else:
    print(max(kouho))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
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)

Submission status: Wrong Answer

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

A_sum=[sum(A[:_+1]) for _ in range(len(A))]
B_sum=[sum(B[:_+1]) for _ in range(len(B))]

temp_b=0

for i in range(1,len(B_sum)):
	if A_sum[0]+B_sum[-i]<=K:
		temp_b=len(B_sum)-i
		break

ans=1+temp_b+1

print(ans)

for i in range(1,len(A_sum)):
	for h in range(len(B_sum)-temp_b,len(B_sum)):
		if A_sum[i]+B_sum[-h]<=K:
			ans=max(ans,i+1+len(B_sum)-h+1)
			break

print(ans)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = 0
for i in range(1, n):
    a[i] += a[i-1]
for i in range(1, m):
    b[i] += b[i-1]
for i in range(n):
    if a[i] > k:
        if i == 0:
            for j in range(m):
                if b[j] > k:
                    break;
                c = j+1
            break;
        else:
            break;
    if m == 0:
        c = max(c, i+1)
        break;
    while a[i]+b[m-1] > k:
        m -= 1    
        if m == 0:
            c = max(c, i+1)
            break;
    c = max(c, i+m+1)
print(c)

Submission status: Wrong Answer

Solution code:
from bisect import *
n, m, k = map(int, input().split())
A = [0]
for x in map(int, input().split()):
    if A[-1]+x <= k: A.append(A[-1]+x)
B = [0]
for x in map(int, input().split()):
    if B[-1]+x <= k: B.append(B[-1]+x)

ans = 0
na = len(A)
nb = len(B)
for i in range(na):
    a = A[i]
    j = bisect_right(B, k-a)
    l = min(nb-1, j)
    b = B[l]
    if a+b <= k:
        ans = max(ans, i+l)
    else:
        ans = max(ans, i+l-1)
    # print('i',i,'a',a,'残',k-a,'j',j,'l',l,'b',b,'i+l',i+l)

# print(k)
# print(A)
# print(B)

print(ans)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.reverse()
c = a + b
d = [0]
for i in range(n + m):
    d.append(d[-1] + c[i])
start = 0
end = n
ans = 0
while end <= n + m:
    while d[end] - d[start] > k:
        start += 1
    else:
        ans = max(ans, end - start)
        end += 1
print(ans)

Submission status: Wrong Answer

Solution code:
def can(x):
    i = min(n,x)
    end = min(m,i)
    t = a[i]+b[x-i]
    for j in range(x-i,end+1):
        t = min(t, a[i]+b[j])
        i -= 1
    if t<=k:
        return True
    else:
        return False

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

lo = 0
hi = n+m
while lo<hi:
    mid=lo+((hi-lo+1)>>1)
    if can(mid):
        lo=mid
    else:
        hi = mid-1
print(lo)

Submission status: Wrong Answer

Solution code:
import itertools

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

sumA = list(itertools.accumulate(A))
sumB = list(itertools.accumulate(B))
ans=0
j=M-1
for i in range(N):
    if sumA[i]>K and i>0:
        break
    while K<sumA[i]+sumB[j] and j>=0:
        j-=1
    ans=max(ans,i+j+2)
print(ans)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = 0
for i in range(1, n):
    a[i] += a[i-1]
for i in range(1, m):
    b[i] += b[i-1]
for i in range(n):
    if a[i] > k:
        if i == 0:
            for j in range(m):
                if b[j] > k:
                    break;
                c = j+1
            break;
        else:
            break;
    if m == 0:
        c = max(c, i)
        break;
    while a[i]+b[m-1] > k:
        m -= 1    
        if m == 0:
            c = max(c, i+1)
            break;
    c = max(c, i+m+1)
print(c)

Submission status: Wrong Answer

Solution code:
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
A.append(10**9+1)
B.append(10**9+1)

Ac = 0
Bc = 0
Time = 0
for _ in range(N+M):
    if A[Ac] > B[Bc]:
        Time += B[Bc]
        Bc += 1
        if Time > K:
            Bc -= 1
            Time -= B[Bc]
            break
    else:
        Time += A[Ac]
        Ac += 1
        if Time > K:
            Ac -= 1
            Time -= A[Ac]
            break
            
print(Ac+Bc)

Submission status: Wrong Answer

Solution code:
import itertools

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

sumA = list(itertools.accumulate(A))
sumB = list(itertools.accumulate(B))
ans=0
j=M-1
for i in range(N):
    if sumA[i]>K:
        break
    while K<sumA[i]+sumB[j] and j>=0:
        j-=1
    ans=max(ans,i+j+2)
print(ans)