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:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
index=0
w=[]
while len(a) or len(b):
	if len(a) and len(b):
		if a[0]<b[0]:
			w.append(a[0])
			a.remove(a[0])
		else:
			w.append(b[0])
			b.remove(b[0])
	elif len(a) and not len(b):
		w.append(a[0])
		a.remove(a[0])
	elif len(b) and not len(a):
		w.append(b[0])
		b.remove(b[0])
count=0
tot=0
for i in range(len(w)):
	tot+=w[i]
	if tot>k:
		break
	count+=1
print(count)

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()))
w=[]
lena=len(a)
lenb=len(b)
for i in range(min(lena,lenb)):
	if a[i]<b[i]:
		w.append(a[i])
		w.append(b[i])
	else:
		w.append(b[i])
		w.append(a[i])

if lena==lenb:
	count=0
	tot=0
	for i in range(len(w)):
		tot+=w[i]
		if tot>k:
			break
		count+=1
	print(count)
	
else:
	m1=min(lena,lenb)
	if m1==lena:
		for j in range(lena,lenb):
			w.append(b[j])
		count=0
		tot=0
		for i in range(len(w)):
			tot+=w[i]
			if tot>k:
				break
			count+=1
		print(count)
	else:
		for j in range(lenb,lena):
			w.append(a[j])
		count=0
		tot=0
		for i in range(len(w)):
			tot+=w[i]
			if tot>k:
				break
			count+=1
		print(count)

Submission status: Wrong Answer

Solution code:
from collections import deque
n, m, k = map(int, input().split())

l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
q1 = deque(l1)
q2 = deque(l2)

ans = 0
sum = 0
for i in range(n + m):
    if q1:
        if q2:
            if q1[0] > q2[0]:
                sum += q2.popleft()
            else:
                sum += q1.popleft()
        else:
            sum += q1.popleft()
    else:
        if q2:
            sum += q2.popleft()
    
    if sum <= k:
        ans += 1


print(ans)

Submission status: Wrong Answer

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

l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))

l = l1 + l2
l.sort()

tmp = 0
ans = 0
if l[0] <= k:
    ans += 1
for i in range(1, n + m):
    l[i] += l[i-1]
    if l[i] <= k:
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
if __name__ == "__main__":
    N, M, K = map(int, input().split())
    input_a = input()
    A = [int(a) for a in input_a.split()]
    input_b = input()
    B = [int(b) for b in input_b.split()]

    read = K
    ans = 0
    for a in A:
        if read >= a:
            read -= a
            ans += 1
        else:
            break 
        for b in B:
            if read >= b:
                read -= b
                ans += 1
            else:
                break 
    print(ans)

Submission status: Wrong Answer

Solution code:
if __name__ == "__main__":
    N, M, K = map(int, input().split())
    input_a = input()
    A = [int(a) for a in input_a.split()]
    input_b = input()
    B = [int(b) for b in input_b.split()]

    read = K
    ans = 0
    for a in A:
        if read > a:
            read -= a
            ans += 1
        else:
            break 
        for b in B:
            if read > b:
                read -= b
                ans += 1
            else:
                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()))

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)

Submission status: Wrong Answer

Solution code:
# 解説
import sys
pin = sys.stdin.readline
pout = sys.stdout.write
perr = sys.stderr.write

N, M, K = map(int, pin().split())
A = list(map(int, pin().split()))
B = list(map(int, pin().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
print(a)
print(b)
for i in range(N + 1):
    #Aの合計がKを超えるまで比較する
    if a[i] > K:
        break
    # 超えていた場合に本の個数を減らす
    while b[M] > K - a[i]:
        M -= 1
    ans = max(ans, M + i)
print(ans)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
from itertools import accumulate
from bisect import bisect_right
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ac=list(accumulate(a))
bc=list(accumulate(b))
temp=0

for i in range(n):
    if ac[i]<=k:
        count=i+1
        count+=bisect_right(bc,k-ac[i])
        temp=max(temp,count)
print(temp)

Submission status: Wrong Answer

Solution code:
import numpy as np

from numba import njit


@njit("i8[:](i8, i8[:], i8[:])", cache=True)
def cumsum(K, A, cA):
    for i, a in enumerate(A):
        cA[i] += cA[i - 1] + A[i]
        if cA[i] > K:
            break

    cA = cA[cA != 0]
    cA = np.append(0, cA)
    return cA


@njit("i8(i8, i8[:], i8[:])", cache=True)
def solve(K, A, cB):
    ans_max = 0
    for i, a in enumerate(A):
        ans = 0
        K -= a
        ind = np.searchsorted(cB, K, side="right") - 1
        ans = i + ind

        if ans > ans_max:
            ans_max = ans

        if ind == 0 or K < 0:
            break

    return ans_max


N, M, K = map(int, input().split())
A = np.array(input().split(), dtype=np.int64)
B = np.array(input().split(), dtype=np.int64)

cB = np.zeros(M, dtype=np.int64)

# np.cumsumだとoverflowする
cB = cumsum(K, B, cB)

A = np.append(0, A)
ans = solve(K, A, cB)
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

from numba import njit


@njit("i8[:](i8, i8[:], i8[:])", cache=True)
def cumsum(K, A, cA):
    for i, a in enumerate(A):
        cA[i] += cA[i - 1] + A[i]
        if cA[i] > K:
            break

    return cA[cA != 0]


@njit("i8(i8, i8[:], i8[:])", cache=True)
def solve(K, A, cB):
    ans_max = 0
    for i, a in enumerate(A):
        ans = 0
        cB += a
        ind = np.searchsorted(cB, K, side="left")
        ans = i + 1 + ind
        cB = cB[: ind + 1]

        if ans > ans_max:
            ans_max = ans

    return ans_max


N, M, K = map(int, input().split())
A = np.array(input().split(), dtype=np.int64)
B = np.array(input().split(), dtype=np.int64)

cB = np.zeros(M, dtype=np.int64)

# np.cumsumだとoverflowする
cB = cumsum(K, B, cB)

ans = solve(K, A, cB)
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()))

sumA = sum(A)

ans = []
best = M

for i in range(N):
  sumB = sum(B)
  for j in range(best):
    S = sumA + sumB
    if S <= K:
      best = j
      ans.append(N+M-i-j)
      break
    sumB -= B[M-1-j]
  sumA -= A[N-1-i]
      
if ans == []:
  print(0)
else:
  print(max(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()))

sumA = sum(A)

ans = []

for i in range(N):
  sumB = sum(B)
  for j in range(M):
    S = sumA + sumB
    if S <= K:
      ans.append(N+M-i-j)
      break
    sumB -= B[M-1-j]
  sumA -= A[N-1-i]
      
if ans == []:
  print(0)
else:
  print(max(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()))

sumA = sum(A)

ans = []

for i in range(N):
  sumB = 0
  sumB = sum(B)
  for j in range(M):
    S = sumA + sumB
    sumB -= B[M-1-j]
    if S > K:
      continue
    else:
      ans.append(N+M-i-j)
      break
  sumA -= A[N-1-i]
      
if ans == []:
  print(0)
else:
  print(max(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()))

sumA = sum(A)

ans = []
print(A,B)

for i in range(N):
  sumB = 0
  sumB = sum(B)
  for j in range(M):
    S = sumA + sumB
    sumB -= B[M-1-j]
    if S > K:
      continue
    else:
      ans.append(N+M-i-j)
      break
  sumA -= A[N-1-i]
      
if ans == []:
  print(0)
else:
  print(max(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()))

sumA = sum(A)

ans = []
print(A,B)

for i in range(N):
  sumB = 0
  sumB = sum(B)
  for j in range(M):
    S = sumA + sumB
    sumB -= B[M-1-j]
    if S > K:
      continue
    else:
      ans.append(N+M-i-j)
      print(sumA,sumB)
      break
  sumA -= A[N-1-i]
      
if ans == []:
  print(0)
else:
  print(max(ans))

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()))
c = a + b
c = sorted(c)
d = [0]
res = 0

for i, elem in enumerate(c):
  d.append(d[i] + elem)
  if d[i + 1] <= k:
    res += 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()))
a_time = [0]
b_time = [0]

for i in range(n):
    a_time.append(a_time[-1] + a[i])
for j in range(m):
    b_time.append(b_time[-1] + b[j])

j = m
cnt = 0

for i in range(n+1):
    while j > 0 and a_time[i] + b_time[j] > k:
        j -= 1
    cnt = max(cnt, i + j)

print(cnt)

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()))
a_time = [0]
b_time = [0]

for i in range(n):
    a_time.append(a_time[-1] + a[i])
for j in range(m):
    b_time.append(b_time[-1] + b[j])

j = m
cnt = 0

for i in range(n+1):
    while i >= 0 and j >= 0 and a_time[i] + b_time[j] > k:
        j -= 1
    cnt = max(cnt, i + j)
print(cnt)

Submission status: Wrong Answer

Solution code:
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

N,M,K=i_map()
A=i_list()
B=i_list()
cum_A = [0]*(N+1)
cum_B = [0]*(M+1)
for i in range(1, N+1):
    cum_A[i] = cum_A[i-1] + A[i-1]
for i in range(1, M+1):
    cum_B[i] = cum_B[i-1] + B[i-1]
ans = 0
for i in range(0, N+1):
    val = K - cum_A[i]
    if val <= 0:
        continue
    idx = bisect_right(cum_B, val) - 1
    ans = max(ans, i + idx)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

N,M,K=i_map()
A=i_list()
B=i_list()
cum_A = [0]*(N+1)
cum_B = [0]*(M+1)
for i in range(1, N+1):
    cum_A[i] = cum_A[i-1] + A[i-1]
for i in range(1, M+1):
    cum_B[i] = cum_B[i-1] + B[i-1]
ans = 0
for i in range(1, N+1):
    val = K - cum_A[i]
    if val <= 0:
        continue
    idx = bisect_right(cum_B, val) - 1
    ans = max(ans, i + idx)
print(ans)

Submission status: Wrong Answer

Solution code:
def solve():
    sum_A = [0 for _ in range(N)]
    sum_B = [0 for _ in range(M)]

    for i in range(N):
        if i == 0:
            sum_A[i] = A[0]
            continue
        sum_A[i] = sum_A[i-1] + A[i]

    for i in range(M):
        if i == 0:
            sum_B[i] = B[0]
            continue
        sum_B[i] = sum_B[i-1] + B[i]

    
    if sum_A[-1] <= K:
        tmp1 = sum_A[-1]
        ans1 = N
    else:
        for i in range(N):
            if sum_A[i] > K:
                if i >= 1:
                    tmp1 = sum_A[i - 1]
                    ans1 = i
                else:
                    tmp1 = 0
                    ans1 = 0
                break
    
    for i in range(M):
        if sum_B[i] + tmp1 > K:
            ans1 += i
            break

    if sum_A[-1] + sum_B[-1] <= K:
        ans1 = N + M

    if sum_B[-1] <= K:
        tmp2 = sum_B[-1]
        ans2 = N

    else:
        for i in range(M):
            if sum_B[i] > K:
                if i >= 1:
                    tmp2 = sum_B[i - 1]
                    ans2 = i
                else:
                    tmp2 = 0
                    ans2 = 0
                break
    
    for i in range(N):
        if sum_A[i] + tmp2 > K:
            ans2 += i
            break

    print(max(ans1, ans2))

if __name__ == "__main__":
    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    solve()

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
an = list(map(int, input().split()))
bm = list(map(int, input().split()))
time = 0
ans = 0
an.append(10**9+1)
bm.append(10**9+1)
while 1:
    time += min(an[0], bm[0])
    if an[0] < bm[0]:
        an.pop(0)
    else:
        bm.pop(0)
    if time <= K:
        ans += 1
    else:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
an = list(map(int, input().split()))
bm = list(map(int, input().split()))
time = 0
ans = 0
an.append(10**9+1)
bm.append(10**9+1)
while K > time:
    time += min(an[0], bm[0])
    if an[0] < bm[0]:
        an.pop(0)
    else:
        bm.pop(0)
    if time <= K:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
an = list(map(int, input().split()))
bm = list(map(int, input().split()))
time = 0
ans = 0
an.append(10**9)
bm.append(10**9)
while K > time:
    time += min(an[0], bm[0])
    if an[0] < bm[0]:
        an.pop(0)
    else:
        bm.pop(0)
    if time <= K:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
a_stack=deque([])
now=0
mn=0
j=0
flag=True
for i in a:
  mn+=i
  if mn>k:
    mn-=i
    flag=None
    break
  else:
    now+=1
    a_stack.append(i)
if flag:
  for i in b:
    mn+=i
    if mn>k:
      mn-=i
      flag=None
      break
    else:
      now+=1
      j+=1
ans=now
while a_stack:
  if j>=m:
    break
  else:
    q=a_stack.pop()
    mn-=q
    now-=1
    while k-mn>0:
      mn+=b[j]
      now+=1
      j+=1
      if k-mn<0:
        now-=1
        mn-=b[j]
        j-=1
      if j==m:
        break
    ans=max(now,ans)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
a_stack=deque([])
now=0
mn=0
j=0
flag=True
for i in a:
  mn+=i
  if mn>k:
    mn-=i
    flag=None
    break
  else:
    now+=1
    a_stack.append(i)
if flag:
  for i in b:
    mn+=i
    if mn>k:
      mn-=i
      flag=None
      break
    else:
      now+=1
      j+=1
ans=now
while a_stack:
  if j>=m:
    break
  else:
    q=a_stack.pop()
    mn-=q
    now-=1
    while k-mn>0:
      mn+=b[j]
      now+=1
      j+=1
      if j==m:
        break
    ans=max(now,ans)
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()))

ans=0
for i in range(N+1):
    if K - sum(a[:i]) > 0:
        for j in range(M,-1,-1):
            if (K - sum(a[:i]) - sum(b[:j]))>=0:
                ans = max(ans,i + j)
                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()))

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

Submission status: Wrong Answer

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
  return int(readline())
n,m,k = readInts()
A = readInts()
B = readInts()
A = [0] + list(accumulate(A))
B = list(accumulate(B))
ans = 0
for i in range(len(A)):
    res = A[i]
    #print('res:',A[i])
    #print(B)
    r = bisect.bisect_right(B, k-res+1)
    #print(r,'\n - - -\n')
    #print(i,r)
    if res <= k:
        ans = max(ans , i+r)
print(ans)

Submission status: Wrong Answer

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
  return int(readline())
n,m,k = readInts()
A = readInts()
B = readInts()
A = [0] + list(accumulate(A))
B = [0] + list(accumulate(B))
ans = 0
for i in range(len(A)):
    res = A[i]
    r = bisect.bisect_right(B, k-res+1)
    #print(i,r)
    if res <= k:
        ans = max(ans , i+r-1)
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
N, M, K = map(int,input().split())
A_list = [0] + list(map(int,input().split()))
B_list = [0] + list(map(int,input().split()))
A_sums_list = list(accumulate(A_list))
B_sums_list = list(accumulate(B_list))
ans = 0
for i, A_sums in enumerate(A_sums_list):
    B_min = -1
    B_max = M + 1
    while True:
        B_index = int((B_max + B_min) * 0.5)
        if A_sums + B_sums_list[B_index] <= K:
            B_min = B_index
        else:
            B_max = B_index
        if B_max - B_min == 1:
            break   
    if i + B_index > ans and A_sums + B_sums_list[B_index] <= K:
        ans = i + B_index
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
N, M, K = map(int,input().split())
A_list = [0] + list(map(int,input().split()))
B_list = [0] + list(map(int,input().split()))
A_sums_list = list(accumulate(A_list))
B_sums_list = list(accumulate(B_list))
ans = 0
for i, A_sums in enumerate(A_sums_list):
    B_min = 0
    B_max = M + 1
    while True:
        B_index = int((B_max + B_min) * 0.5)
        if A_sums + B_sums_list[B_index] <= K:
            B_min = B_index
        else:
            B_max = B_index
        if B_max - B_min == 1:
            break   
    if A_sums + B_sums_list[B_min] <= K:
        ans = i + B_min
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
N, M, K = map(int,input().split())
A_list = [0] + list(map(int,input().split()))
B_list = [0] + list(map(int,input().split()))
A_sums_list = list(accumulate(A_list))
B_sums_list = list(accumulate(B_list))
ans = 0
for i, A_sums in enumerate(A_sums_list):
    B_min = 0
    B_max = M + 1
    while True:
        B_index = int((B_max + B_min) * 0.5)
        if A_sums + B_sums_list[B_index] <= K:
            B_min = B_index
        else:
            B_max = B_index
        if B_max - B_min == 1:
            break   
    if i + B_min > ans and B_min != 0:
        ans = i + B_min
print(ans)

Submission status: Wrong Answer

Solution code:
#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))
  
n,m,k=input2()
A=input_array()
B=input_array()
acc_A=[0]*n
acc_B=[0]*m
acc_A[0]=A[0]
acc_B[0]=B[0]

for i in range(1,n):
	acc_A[i]=acc_A[i-1]+A[i]
for i in range(1,m):
	acc_B[i]=acc_B[i-1]+B[i]

ans=0
tmp_m=m-1
for i in range(n):
	if acc_A[i]>k:
		break
	for j in range(tmp_m,-1,-1):
		if acc_B[j]<=k-acc_A[i]:
			ans=max(i+j+2,ans)
			tmp_m=j
			break
print(ans)

Submission status: Wrong Answer

Solution code:
#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))
  
n,m,k=input2()
A=input_array()
B=input_array()
acc_A=[0]*n
acc_B=[0]*m
acc_A[0]=A[0]
acc_B[0]=B[0]

for i in range(1,n):
	acc_A[i]=acc_A[i-1]+A[i]
for i in range(1,m):
	acc_B[i]=acc_B[i-1]+B[i]

ans=0
for i in range(n):
	if acc_A[i]>k:
		break
	for j in range(m-1,-1,-1):
		if acc_B[j]<=k-acc_A[i]:
			ans=max(i+j+2,ans)
			break
print(ans)

Submission status: Wrong Answer

Solution code:
#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))
  
n,m,k=input2()
A=input_array()
B=input_array()
acc_A=[0]*n
acc_B=[0]*m
acc_A[0]=A[0]
acc_B[0]=B[0]

for i in range(1,n):
	acc_A[i]=acc_A[i-1]+A[i]
for i in range(1,m):
	acc_B[i]=acc_B[i-1]+B[i]

ans=0
for i in range(n):
	if acc_A[i]>k:
		break
	for j in range(m):
		if acc_B[j]<=k-acc_A[i]:
			ans=max(i+j+2,ans)
		else:
			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()))

count =0
a_count=0
b_count=0
ans=0 

while count<=K:
    if a_count == N and b_count == M:
        ans+=1
        break
    elif a_count == N:
        count += B[0]
        B.remove(B[0])
        b_count+=1
        ans +=1       
    elif b_count == M:
        count += A[0]
        A.remove(A[0])
        a_count+=1
        ans +=1    
    elif A[0] < B[0]:
        count += A[0]
        A.remove(A[0])
        a_count+=1
        ans +=1
    elif B[0] <= A[0]:
        count += B[0]
        B.remove(B[0])
        b_count+=1
        ans +=1
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()))

count =0
a_count=0
b_count=0
ans=0 
while count<=K:
    if a_count == N and b_count == M:
        ans+=1
        break
    elif a_count == N:
        count += B[0]
        B.remove(B[0])
        b_count+=1
        ans +=1       
    elif b_count == M:
        count += A[0]
        A.remove(A[0])
        a_count+=1
        ans +=1    
    elif A[0] < B[0]:
        count += A[0]
        A.remove(A[0])
        a_count+=1
        ans +=1
    elif B[0] <= A[0]:
        count += B[0]
        B.remove(B[0])
        b_count+=1
        ans +=1
print(ans-1)

Submission status: Wrong Answer

Solution code:
import bisect
from typing import List


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


def t(n: int, m: int, k: int, a: List[int], b: List[int]) -> int:
    aa = [a[0]]
    for i in range(n - 1):
        aa.append(aa[i] + a[i + 1])
    bb = [b[0]]
    for i in range(m - 1):
        bb.append(bb[i] + b[i + 1])

    ret = 0
    for i in range(n):
        x = aa[i]
        s = k - x
        if s < 0:
            continue
        j = bisect.bisect(bb, s) - 1
        ret = max(ret, i + 1 + j + 1)

    return ret


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import bisect
from typing import List


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


def t(n: int, m: int, k: int, a: List[int], b: List[int]) -> int:
    aa = [a[0]]
    for i in range(n - 1):
        aa.append(aa[i] + a[i + 1])
    bb = [b[0]]
    for i in range(m - 1):
        bb.append(bb[i] + b[i + 1])

    ret = 0
    for i in range(n):
        x = aa[i]
        s = k - x
        if s < 0:
            break
        j = bisect.bisect(bb, s) - 1
        ret = max(ret, i + 1 + j + 1)

    return ret


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()))
t=0
c=0
i=0
j=0

if K<A[0] and K<B[0]:
  print(c)
  exit()

while 1:
  if t>=K:
    print(c)
    break
  else:
    if i==N and j==M:
      print(c)
      break
    elif i==N:
      t=t+B[j]
      B[j]=0
      j=j+1
      c=c+1
    elif j==M:
      t=t+A[i]
      A[i]=0
      i=i+1
      c=c+1
    else:
      if A[i]>=B[j]:
        t=t+A[i]
        A[i]=0
        i=i+1
        c=c+1
      else:
        t=t+B[j]
        B[j]=0
        j=j+1
        c=c+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()))
t=0
c=0
while 1:
  if t>K:
    print(c-1)
    break
  elif t==K:
    print(c)
    break
  else:
    if len(A)==0:
      t=t+B[0]
      B.remove(B[0])
      c=c+1
    elif len(B)==0:
      t=t+A[0]
      A.remove(A[0])
      c=c+1
    else:
      if A[0]>=B[0]:
        t=t+A[0]
        A.remove(A[0])
        c=c+1
      else:
        t=t+B[0]
        B.remove(B[0])
        c=c+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()))
c = a[::-1] + b
d = [0] * (len(c)+1)
for i in range(len(c)):
    d[i+1] = d[i] + c[i]
l = 0
r = n+1
mx = 0
while r < len(d) - 1 and l <= n:
    if (d[r+1] - d[l] <= k):
        r += 1
        if mx < r - l:
            mx = r-l
    else:
        l += 1
        if l > r:
            r = l
        if (d[r] - d[l] < k):
            if mx < r - l:
                mx = r-l
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()))
c = a[::-1] + b
d = [0] * (len(c)+1)
for i in range(len(c)):
    d[i+1] = d[i] + c[i]
l = 0
r = n+1
mx = 0
while r < len(d)-1 and l <= n:
    if (d[r+1] - d[l] <= k):
        r += 1
        if mx < r - l:
            mx = r-l
    else:
        l += 1
        if l > r:
            r = l

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()))
c = a[::-1] + b
d = [0] * (len(c)+1)
for i in range(len(c)):
    d[i+1] = d[i] + c[i]
l = 0
r = 0
mx = 0
while r < len(d)-1 and l <= n:
    if (d[r+1] - d[l] <= k):
        r += 1
    else:
        l += 1
        if l > r:
            r = l
    if mx < r - l:
        mx = r-l

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()))
c = a[::-1] + b
d = [0] * (len(c)+1)
for i in range(len(c)):
    d[i+1] = d[i] + c[i]
l = 0
r = 0
mx = 0
while r < len(d)-1:
    if (d[r+1] - d[l] <= k):
        r += 1
    else:
        l += 1
        if l > r:
            r += 1
    if mx < r - l:
        mx = r-l

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