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:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import itertools
from decimal import *

input = sys.stdin.readline

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
def inputStr(): return input()[:-1]

inf = float('inf')
mod = 1000000007

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

def main():
	N,M,K = inputMap()
	A = inputList()
	B = inputList()

	A.append(inf)
	B.append(inf)

	ans = 0
	times = 0

	while True:
		if times > K:
			break

		if A[0] < B[0]:
			times += A[0]
			A = A[1:]
		else:
			times += B[0]
			B = B[1:]
		#print(times)
		ans += 1

	print(ans-1)



#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
a=[int(j)for j in input().split()]
b=[int(j)for j in input().split()]
from itertools import accumulate
a=[0]+list(accumulate(a))
b=list(accumulate(b))
ans=0
import bisect
for i,j in enumerate(a):
    if k-j>0:
        idx=bisect.bisect_right(b,k-j)
        ans=max(ans,i+idx)
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import itertools
from decimal import *

input = sys.stdin.readline

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
def inputStr(): return input()[:-1]

inf = float('inf')
mod = 1000000007

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

def main():
	N,M,K = inputMap()
	A = inputList()
	B = inputList()

	ans = 0
	times = 0
	flg = False

	while True:
		if times > K:
			print("sss")
			break

		lenA = len(A)
		lenB = len(B)

		if lenA <= 0 and lenB <= 0:
			flg = True
			break
		elif lenA <= 0:
			times += B[0]
			B = B[1:]
		elif lenB <= 0:
			times += A[0]
			A = A[1:]
		else:
			if A[0] < B[0]:
				times += A[0]
				A = A[1:]
			else:
				times += B[0]
				B = B[1:]
		#print(times)
		ans += 1

	if flg == True:
		print(ans)
	else:
		print(ans-1)



#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
from collections import deque

n, m, k = map(int, input().split())
a = deque(map(int, input().split()))
b = deque(map(int, input().split()))
 
times = 0
count = 0
while times <= k:
  if len(a) == 0 and len(b) == 0:
    count = count + 1
    break
  if len(a) == 0:
    times = times + b[0]
    b.popleft()
    count = count + 1
    continue
  if len(b) == 0:
    times = times + a[0]
    a.popleft()
    count = count + 1
    continue
  if a[0] < b[0]:
    times = times + a[0]
    a.popleft()
    count = count + 1
  else:
    times = times + b[0]
    b.popleft()
    count = count + 1
   

print(count-1)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import itertools
from decimal import *

input = sys.stdin.readline

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
def inputStr(): return input()[:-1]

inf = float('inf')
mod = 1000000007

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

def main():
	N,M,K = inputMap()
	A = inputList()
	B = inputList()

	ans = 0
	times = 0
	markA = 0
	markB = 0

	while True:
		if times > K:
			break

		if len(A) <= 0 and len(B) <= 0:
			break
		elif len(A) <= 0:
			times += B[markB]
			B = B[1:]
		elif len(B) <= 0:
			times += A[markA]
			A = A[1:]
		else:
			if A[markA] < B[markB]:
				times += A[markA]
				A = A[1:]
			else:
				times += B[markB]
				B = B[1:]
		#print(times)
		ans += 1

	print(ans-1)



#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
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()))
time=0
count=0
l=len(a)+len(b)
for i in range(l):
    if len(b)>0:
        if len(a)>0:
            if a[0]<b[0]:
                if time+a[0]<=k:
                    time+=a[0]
                    a.pop(0)
                else:
                    break
            else:
                if time+b[0]<=k:
                    time+=b[0]
                    b.pop(0)
                else:
                    break
        else:
            if time+b[0]<=k:
                time+=b[0]
                b.pop(0)
            else:
                break
    elif len(a)>0:
        if time+a[0]<=k:
            time+=a[0]
            a.pop(0)
        else:
            break
    else:
        break
    count+=1
print(count)

Submission status: Wrong Answer

Solution code:
import itertools
import math
 
n, m, k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
 
max_b = 0
 
a_cum = list(itertools.accumulate(a))
b_cum = [0] + list(itertools.accumulate(b))
 
j = m
for i in range(n):
    if a_cum[i] > k:
        break
    while b_cum[j] > k - a_cum[i]:
        j -= 1
 
    max_b = max(max_b,j+i+1)
print(max_b)

Submission status: Wrong Answer

Solution code:
import itertools
import math

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

max_b = 0

a_cum = list(itertools.accumulate(a))
b_cum = [0] + list(itertools.accumulate(b))

j = m
for i in range(n):
    if a_cum[i] > k:
        break
    while b_cum[j]+a_cum[i] > k:
        j -= 1

    max_b = max(max_b,j+i+1)
print(max_b)

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()))
time=0
count=0
while True:
    if len(b)>0:
        if len(a)>0:
            if a[0]<b[0]:
                if time+a[0]<=k:
                    time+=a[0]
                    a.pop(0)
                else:
                    break
            else:
                if time+b[0]<=k:
                    time+=b[0]
                    b.pop(0)
                else:
                    break
        else:
            if time+b[0]<=k:
                time+=b[0]
                b.pop(0)
            else:
                break
    elif len(a)>0:
        if time+a[0]<=k:
            time+=a[0]
            a.pop(0)
        else:
            break
    else:
        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()))

a.insert(0, 0)
b.insert(0, 0)

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 numpy as np
import itertools
import math

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

time = float(0)
max_b = 0

a_cum = np.cumsum(a)
b_cum = np.cumsum(b)

times = list(itertools.product(a_cum,b_cum))
for i,d in enumerate(times):
    r_time = d[0] + d[1]
    if not r_time > k and max_b < math.ceil((i+1)/(len(times)//n))+(i%m)+1:
        max_b = math.ceil((i+1)/(len(times)//n))+(i%m)+1

print(max_b)

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()))
x = 0
y = 0
cnt = 0
cnt2 = 0
sumlist_a = [0]
sumlist_b = [0]

for i in range(n):
    x += a[i]
    if x > k:
        break
    sumlist_a.append(x)
a_available = len(sumlist_a)

for j in range(m):
    y += b[j]
    if y > k:
        break
    sumlist_b.append(y)


ans = 0
best_pos = len(sumlist_b)
#a全部本をとってこれる最大個数
for i in range(len(sumlist_a)):
    time = sumlist_a[i]
    current_ans = i
    for j in range(best_pos):
        if (time + sumlist_b[j]) > k:
            current_ans += j
            best_pos = j-1
            break
        if j == len(sumlist_b)-1:
            current_ans += j
    ans = max(ans, current_ans)
print(ans)

# p=0
# for i in sumlist_a:
#     while y < k - i:
#         y += b[cnt2]
#         print(y)
#         if y > k - i:
#             break
#         cnt2 += 1
#         if cnt2 == m:
#             break
#     ans = max(ans, len(sumlist_a)-1+cnt2-p)
#     p += 1
#     cnt2 = 0
# print(ans)

Submission status: Wrong Answer

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

i = 0
j = 0
ans = 0

while k > 0:
    if i <= n-1 and j <= m-1:
        k -= min(a_lsit[i], b_list[j])
        #print(k)
        if a_lsit[i] < b_list[j]:
            i += 1
        else:
            j += 1
    elif i > n-1:
        k -= b_list[j]
        #print(k)
        j += 1
    elif j > m-1:
        k -= a_lsit[i]
        #print(k)
        i += 1

    if k < 0:
        break

    ans += 1
    
print(int(ans))

Submission status: Wrong Answer

Solution code:
import numpy as np

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

time = float(0)
max_b = 0

a_cum = np.cumsum(a)
b_cum = np.cumsum(b)

for i in range(n):
    for j in range(m):
        r_time = a_cum[i] + b_cum[j]
        if not r_time > k and max_b < i+j:
            max_b = i+j

print(max_b+2)

Submission status: Wrong Answer

Solution code:
from sys import stdin
input = stdin.readline

def accumulate(l, X):
    acclist = [0]*(l+1)
    for i in range(1,l+1):
        acclist[i] = acclist[i-1] + X[i]
    return acclist

N,M,K = map(int, input().split())
A = [0] + list(map(int, input().split()))
B = [0] + list(map(int, input().split()))

X = accumulate(N, A)
Y = accumulate(M, B)

maxbook = 0
j = M
for i in range(N+1):
    x = X[i]
    y = Y[j]
    while x + y > K:
        j -= 1 
        y = Y[j]
        if j <= 0:
            break
    if j <= 0:
        break

    maxbook = max(maxbook, i + j)

print(maxbook)

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

s = 0
cnt = 0

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

while s <= k:
    if len(a) == 0 or len(b) == 0:
        break
    if a[0] < b[0]:
        s += a[0]
        cnt += 1
        a.pop(0)
    else:
        s += b[0]
        cnt += 1
        b.pop(0)
cnt -= 1

while len(a) != 0 and s <= k:
    s += a[0]
    cnt += 1
    a.pop(0)

while len(b) != 0 and s <= k:
    s += b[0]
    cnt += 1
    b.pop(0)

print(cnt)

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

ta = [0]
ita = 0
tb = []
itb = 0
for i in a:
    ita += i
    ta.append(ita)
for j in b:
    itb += j
    tb.append(itb)

ans = 0
for l, x in enumerate(ta):
    if k <= x:
        continue
    for y in tb:
        if k >= x + y:
            l += 1
        else:
            break
    ans = max(ans, l)
print(ans)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
a = list(map(int, input().split())) + [10**10]
b = list(map(int, input().split())) + [10**10]
a.reverse()
b.reverse()
ans = 0
t = 0
while t + min(a[-1], b[-1]) <= k:
	t += min(a[-1], b[-1])
	if a[-1] <= b[-1]:
		a.pop()
	else:
		b.pop()
	ans += 1
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 = [0]*(n+1)
b = [0]*(m+1)

for i in range(n):
    a[i+1] = a[i] + A[i]
for i in range(m):
    b[i+1] = b[i] + B[i]

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

for i in range(n):
    a[i+1] = a[i] + A[i]
for i in range(m):
    b[i+1] = b[i] + B[i]

ans = 0
best = m
for i in range(n+1):
    if k < a[i]:
        break
    for j in range(best,-1,-1):
        if b[j] <= k-a[i]:
            break
    ans = max(ans,i+j)
    best = j
    if not best:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
import sys
from itertools import accumulate

input = sys.stdin.readline


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

    B_cumsum = list(accumulate(B))
    ans = 0
    time = 0
    for i, a in enumerate(A, start=1):
        time += a
        if time > K:
            break
        j = bisect.bisect_right(B_cumsum, K - time)
        ans = max(ans, i + j)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
input = sys.stdin.readline

N, M, K = map(int, input().split())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))


A_list.insert(0, 0)
B_list.insert(0, 0)
B_cumsum = np.cumsum(B_list)

time = B_cumsum[-1]
ans, j = 0, M

for i in range(N+1):
    if (time > K):
        break
    while (j > 0 and time > K):
        time -= B_list[j]
        j -= 1

    ans = max(ans, i+j)
    time += A_list[i]

print(ans)

Submission status: Wrong Answer

Solution code:
n,m,k = map(int,input().split())
c = []
a = list(map(int,input().split()))
for x in a:
    c.append(x)
b = list(map(int,input().split()))
for x in b:
    c.append(x)
c.sort()
cc = 0
ans = 0
for x in c:
    cc += x
    ans = ans + 1
    if cc >= k:
        if cc > k:
            print(ans-1)
            break
        else:
            print(ans)
            break
    else:
        pass

Submission status: Wrong Answer

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

cost = 0
res = 0
while cost < k:
  if a_lst != []:
    if b_lst != []:
      if a_lst[0] < b_lst[0]:
        if a_lst[0] + cost > k:
          break
        cost += a_lst.pop(0)
        res += 1
      else:
        if b_lst[0] + cost > k:
          break
        cost += b_lst.pop(0)
        res += 1
    else:
      if a_lst[0] + cost > k:
        break
      cost += a_lst.pop(0)
      res += 1
  else:
    if b_lst != []:
      if b_lst[0] + cost > k:
        break
      cost += b_lst.pop(0)
      res += 1
    else:
      break   
print(res)

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:
n, m, k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

time = float(0)
books = []
i = 0
j = 0

while(True):
    if i < n:
        a_t = a[i]
    else:
        a_t = float('inf')
    if j < m:
        b_t = b[j]
    else:
        b_t = float('inf')

    if a_t == float('inf') and b_t == float('inf'):
        break

    if a_t < b_t:
        books.append(a[i])
        i += 1
    else:
        books.append(b[j])
        j += 1

count = 0
for t in books:
    if not time + t > k:
        time += t
        count += 1

print(count)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
def main():
    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 + M + 1):
        flag = 0
        for j in range(i + 1):
            if sum(A[0: j]) + sum(A[0: i - j]) <= K:
                flag = 1
                break
        if flag == 0:
            i -= 1
            break
    print(i)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import itertools
import bisect

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

a_sum = [0] + list(itertools.accumulate(A))
b_sum = [0] + list(itertools.accumulate(B))

ans= 0

for i in range(n+1):
    tmp = bisect.bisect_right(b_sum, k - a_sum[i]) - 1
    if i + tmp > ans:
        ans = i + tmp

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import deque
def main():
    N, M, K = map(int, readline().split())
    A = [int(i) for i in readline().split()]
    B = [int(i) for i in readline().split()]

    #方針:A,Bそれぞれ前からi,j番目までとったときの合計がK以内であるときのi+jを求める
    #A,Bそれぞれの山の一番上の本だけを比較して時間が小さい方を選ぶことを繰り返すのは間違い。

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

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

    mx = 0
    for i in range(N+1):
        # r:= Aの山の上からi番目までの本を読むとき、残りの時間
        r = K-csumA[i]
        if r < 0:
            continue
        left = -1
        right = M+1
        while right-left>1: 
            mid = (left+right)//2
            if r >= csumB[mid]:
                left = mid
            else:
                right = mid

        if r > 0: 
            mx = max(mx, i+left)
    print(mx)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import deque
def main():
    N, M, K = map(int, readline().split())
    A = [int(i) for i in readline().split()]
    B = [int(i) for i in readline().split()]

    #方針:A,Bそれぞれ前からi,j番目までとったときの合計がK以内であるときのi+jを求める
    #A,Bそれぞれの山の一番上の本だけを比較して時間が小さい方を選ぶことを繰り返すのは間違い。

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

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

    mx = 0
    for i in range(N+1):
        # r:= Aの山の上からi番目までの本を読むとき、残りの時間
        r = K-csumA[i]

        left = -1
        right = M+1
        while right-left>1: 
            mid = (left+right)//2
            if r >= csumB[mid]:
                left = mid
            else:
                right = mid

        if r > 0: 
            mx = max(mx, i+left)
    print(mx)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
input = sys.stdin.readline

N, M, K = map(int, input().split())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))


#N, M, K = 3, 4, 730
#A_list = [60, 90, 120]
#B_list = [80, 150, 80, 150]

#N, M, K = 5, 4, 1
#A_list = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000]
#B_list = [1000000000, 1000000000, 1000000000, 1000000000]


A_list.insert(0, 0)
B_list.insert(0, 0)
B_cumsum = np.cumsum(B_list)

time = B_cumsum[-1]
ans, j = 0, M

for i in range(N+1):
    while ((j > 0) and (time > K)):
        j -= 1
        time -= B_list[j]
    if (time > K):
        break
    ans = max(ans, i+j)
    time += A_list[i]

print(ans)

Submission status: Wrong Answer

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

# Bの本を上から読んでいった時の累積時間をリストに入れる
B_acc = [0] * M
B_acc[0] = B[0]
for i in range(1, M):
  B_acc[i] = B_acc[i-1] + B[i]

A_acc = 0
count_max = 0
for i in range(N):
  A_acc += A[i]
  if K - A_acc >= 0:
    count = (i + 1) + bisect.bisect(B_acc, K - A_acc)
    count_max = max(count_max, count)
  else:
    break
print(count_max)

Submission status: Wrong Answer

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

a=[sum(A[:n]) for n in range(N+1)]
b=[sum(B[:m]) for m in range(M+1)]
num=0
bmax=M+1
for n in range(1,N+1):
    for m in reversed(range(1,bmax)):
        if b[m]<=K-a[n]:
            num=max(num,n+m)
            bmax=m+1
            break
print(num)

Submission status: Wrong Answer

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

# Bの本を上から読んでいった時の累積時間をリストに入れる
B_acc = [0] * M
B_acc[0] = B[0]
for i in range(1, M):
  B_acc[i] = B_acc[i-1] + B[i]

A_acc = 0
count_max = 0
for i in range(N):
  A_acc += A[i]
  if K - A_acc > 0:
    count = (i + 1) + bisect.bisect(B_acc, K - A_acc)
    count_max = max(count_max, count)
  else:
    break
print(count_max)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
input = sys.stdin.readline

N, M, K = map(int, input().split())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))


#N, M, K = 3, 4, 730
#A_list = [60, 90, 120]
#B_list = [80, 150, 80, 150]

#N, M, K = 5, 4, 1
#A_list = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000]
#B_list = [1000000000, 1000000000, 1000000000, 1000000000]


A_list.insert(0, 0)
B_list.insert(0, 0)
B_cumsum = np.cumsum(B_list)

time = B_cumsum[-1]
ans, j = 0, M

for i in range(N+1):
    while (j > 0 and time > K):
        j -= 1
        time -= B_list[j]
    if (time > K):
        break
    ans = max(ans, i+j)
    time += A_list[i]

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
input = sys.stdin.readline

N, M, K = map(int, input().split())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))


#N, M, K = 3, 4, 730
#A_list = [60, 90, 120]
#B_list = [80, 150, 80, 150]

#N, M, K = 5, 4, 1
#A_list = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000]
#B_list = [1000000000, 1000000000, 1000000000, 1000000000]


A_list.insert(0, 0)
B_list.insert(0, 0)
B_cumsum = np.cumsum(B_list)

time = B_cumsum[-1]
ans, j = 0, M

for i in range(N+1):
    while (j > 0 and time > K):
        j -= 1
        time -= B_list[j]
    if (time > K):
        break
    ans = max(ans, i+j)
    if i == N:
        break
    time += A_list[i]

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import deque
def main():
    N, M, K = map(int, readline().split())
    A = [int(i) for i in readline().split()]
    B = [int(i) for i in readline().split()]

    #方針:A,Bそれぞれ前からi,j番目までとったときの合計がK以内であるときのi+jを求める
    #A,Bそれぞれの山の一番上の本だけを比較して時間が小さい方を選ぶことを繰り返すのは間違い。

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

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

    mx = 0
    for i in range(N+1):
        # r:= Aの山の上からi番目までの本を読むとき、残りの時間
        r = K-csumA[i]

        if r <= 0:
            j = 0
        else:
            j = i

        left = 0
        right = M+1
        while right-left>1: 
            mid = (left+right)//2
            if r >= csumB[mid]:
                left = mid
            else:
                right = mid
        mx = max(mx, j+left)
    print(mx)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
A=[0]+list(map(int,input().split()))
B=[0]+list(map(int,input().split()))

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

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

ans=0
start1=0
goal1=n+1
for a_cnt in range(n+1):
    start2=0
    goal2=m+1
    b_cnt=(start2+goal2)//2
    while start2!=goal2 and b_cnt<m:
        b_cnt=min((start2+goal2)//2,m)
        if A[a_cnt]+B[b_cnt]>k:
            goal2=b_cnt
        else:
            start2+=b_cnt+1
            ans=max(ans,a_cnt+b_cnt)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import deque
def main():
    N, M, K = map(int, readline().split())
    A = [int(i) for i in readline().split()]
    B = [int(i) for i in readline().split()]

    #方針:A,Bそれぞれ前からi,j番目までとったときの合計がK以内であるときのi+jを求める
    #A,Bそれぞれの山の一番上の本だけを比較して時間が小さい方を選ぶことを繰り返すのは間違い。

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

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

    mx = 0
    for i in range(N+1):
        # r:= Aの山の上からi番目までの本を読むとき、残りの時間
        r = K-csumA[i]

        if r <= 0:
            j = 0
        else:
            j = i

        left = -1
        right = M+1
        while right-left>1: 
            mid = (left+right)//2
            if r >= csumB[mid]:
                left = mid
            else:
                right = mid
        mx = max(mx, j+left)
    print(mx)

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()))
time = []
#print(time.pop(1))
count = int()

while K - sum(time) >= 0:
    if sum(A) == 0:
        if sum(B) == 0:
            break
        if K - sum(time) >= min(B):
            #print('B:', B)
            time.append(min(B))
            B.pop(0)
            count += 1
            #print('K - sum(time)b:', K - sum(time))
            print('最終結果：A', A, '最終結果：B', B, '残時間：', K - sum(time))
            continue


    elif sum(B) == 0:
        if sum(A) == 0:
            break
        if K - sum(time) >= min(A):
            #print('A:', A)
            time.append(min(A))
            A.pop(0)
            count += 1
            #print('K - sum(time)a:', K - sum(time))
            print('最終結果：A', A, '最終結果：B', B, '残時間：', K - sum(time))
            continue

    else:
        if min(A) >= min(B):
            if K - sum(time) >= min(B):
                # print('B:', B)
                time.append(min(B))
                B.pop(0)
                count += 1
                # print('K - sum(time)b:', K - sum(time))
                print('最終結果：A', A, '最終結果：B', B, '残時間：', K - sum(time))
                continue
            else:
                break
        else:
            if K - sum(time) >= min(A):
                # print('A:', A)
                time.append(min(A))
                A.pop(0)
                count += 1
                # print('K - sum(time)a:', K - sum(time))
                print('最終結果：A', A, '最終結果：B', B, '残時間：', K - sum(time))
                continue
            else:
                break

print(count)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
A=[0]+list(map(int,input().split()))
B=[0]+list(map(int,input().split()))

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

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

ans=0
for a_cnt in range(n+1):
    start=0
    goal=n+1
    b_cnt=(start+goal)//2
    while start!=goal and b_cnt<m+1:
        b_cnt=(start+goal)//2
        if A[min(a_cnt,n)]+B[min(b_cnt,m)]>k:
            goal=b_cnt
        else:
            start+=b_cnt+1
            ans=max(ans,min(a_cnt,n)+min(b_cnt,m))
print(ans)