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:
import bisect

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
for i in range(1, N):
    A[i] = A[i] + A[i-1]
B = list(map(int, input().split()))
for i in range(1, M):
    B[i] = B[i] + B[i-1]

ans = 0
for i in range(N):
    if A[i] > K:
        break
    temp = K - A[i]
    val = bisect.bisect_right(B, temp)
    ans = max(ans, (i+1)+val)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
# from math import sqrt, gcd, ceil, log
from bisect import bisect
from collections import defaultdict, Counter
inp = sys.stdin.readline
read = lambda: list(map(int, inp().strip().split()))

# sys.setrecursionlimit(10**6)



def solve():
	n, m, k = read()
	arr1 = read(); arr2 = read()
	for i in range(1, n):arr1[i] += arr1[i-1]
	for i in range(1, m):arr2[i] += arr2[i-1]
	i = 0; ans = 0
	while i < n and arr1[i] <= k:
		tem = i + bisect(arr2, k-arr1[i])+1
		# print(tem, i, arr1[i], bisect(arr2, k-arr1[i]))
		ans = max(ans, tem)
		i += 1
	print(ans)

	





		

if __name__ == "__main__":
	solve()

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()))
for i in range(1,n):
    a[i] += a[i-1]
for i in range(1,m):
    b[i] += b[i-1]
a = [0]+a
b = [0]+b

ans = 0
ALL = 0
from bisect import bisect
for i in range(1,n+1):
    ALL = a[i]
    if ALL > k:
        continue
    idx = bisect(b,k-ALL)
    #print(i,ALL,idx)
    ans = max(ans,i+idx-1)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
# from math import sqrt, gcd, ceil, log
from bisect import bisect
from collections import defaultdict, Counter
inp = sys.stdin.readline
read = lambda: list(map(int, inp().strip().split()))

# sys.setrecursionlimit(10**6)



def solve():
	n, m, k = read()
	arr1 = read(); arr2 = read()
	for i in range(1, n):arr1[i] += arr1[i-1]
	for i in range(1, m):arr2[i] += arr2[i-1]
	i = 0; ans = 0
	while i < n and arr1[i] < k:
		tem = i + bisect(arr2, k-arr1[i])+1
		ans = max(ans, tem)
		i += 1
	print(ans)

	





		

if __name__ == "__main__":
	solve()

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

answer = 0
cost = 0
index_a = 0
for i in range(len(A)):
    if i == len(A) or cost + A[i] > K:
        break
    cost += A[i]
    answer += 1
    index_a = i

max_answer = answer
index_b = 0
while (index_b < len(B) and index_a >= 0):
    if cost + B[index_b] > K:
        cost -= A[index_a]
        index_a -= 1
        answer -= 1
    else:
        cost += B[index_b]
        index_b += 1
        answer += 1
    if max_answer < answer:
        max_answer = answer
print(max_answer)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
all_book = 200000 * 2 # 最大の本の数(N + M の最大)

# A,Bのリストの順序を逆にする
A.sort(reverse=True)
B.sort(reverse=True)

k = 0
count = 0
select = list()
for i in range(all_book):
  if len(A) == 0 and len(B) == 0:
    break
  elif len(A) == 0:
    # Bの本のみ
    select = B
  elif len(B) == 0:
    # Aの本のみ
    select = A
  elif A[len(A) - 1] <= B[len(B) - 1]:
    # BよりもAの方が早く読める(同じも含む)
    select = A
  elif A[len(A) - 1] > B[len(B) - 1]:
    select = B
  k += select[len(select) - 1]
  if k <= K:
    count += 1
  else:
    break
  select.pop()
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()))
for i in range(1,n):
    a[i] += a[i-1]
for i in range(1,m):
    b[i] += b[i-1]
a = [0]+a
b = [0]+b

ans = 0
ALL = 0
from bisect import bisect
for i in range(1,n+1):
    ALL = a[i]
    if ALL > k:
        continue
    else:
        idx = bisect(b,k-ALL)
        #print(i,ALL,idx)
    ans = max(ans,i+idx-1)
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools,sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N,M,K = LI()
A = LI()
B = LI()
accumulate_A = list(itertools.accumulate(A))
accumulate_B = list(itertools.accumulate(B))
ans,j = 0,M-1
for i in range(N):
    if accumulate_A[i]>K:
        break
    while accumulate_A[i]+accumulate_B[j]>K:
        j -= 1
        if j<0:
            break
    ans = max(ans,i+j+2)
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
data = stdin.readlines()

n = int(data[0].split()[0])
m = int(data[0].split()[1])

k = int(data[0].split()[2])

A = [int(s) for s in data[1].split()]
B = [int(s) for s in data[2].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])
a.pop(0)
b.pop(0)

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

answer = 0
cost = 0
index_a = 0
for i in range(len(A)):
    if i == len(A) or cost + A[i] > K:
        break
    cost += A[i]
    answer += 1
    index_a = i

max_answer = answer
index_b = 0
while (index_b < len(B) and index_a >= 0 and cost > 0):
    if cost + B[index_b] > K:
        cost -= A[index_a]
        index_a -= 1
        answer -= 1
    else:
        cost += B[index_b]
        index_b += 1
        answer += 1
    if max_answer < answer:
        max_answer = answer
print(max_answer)

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
ares = 0
bres = 0
bsatu = 0
time2 = 0
res = []
for i in range(0,n): #Aで最高何冊読めるか
    if sum(a[n-i:]) < k and k <= sum(a[n-i-1:]):
        ares = i
print(ares)
for i in range(0,ares+1): #0からaresまで
    asatu = ares - i
    bsatu = 0
    time2 = sum(a[n-asatu:])
    bsatu += 1
    if time >= k:
        break
    res += [asatu + bsatu]
print(res)

Submission status: Wrong Answer

Solution code:
import itertools,sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N,M,K = LI()
A = LI()
B = LI()
accumulate_A = list(itertools.accumulate(A))
accumulate_B = list(itertools.accumulate(B))
countA,countB,_sumA,_sumB = 0,0,0,0
ans,j = 0,M-1
for i in range(N):
    if accumulate_A[i]>K:
        break
    while accumulate_A[i]+accumulate_B[j]>K:
        j -= 1
        if j<0:
            break
    ans = max(ans,i+j+2)
print(ans)

Submission status: Wrong Answer

Solution code:

from bisect import bisect_right
from itertools import accumulate
def resolve():
    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    cum_B = list(accumulate(B))

    ans = 0
    for i in range(1, N+1):
        cnt = 0
        limit = 0
        if K - sum(A[:i]) >= 0:
            cnt = i
            limit = K - sum(A[:i])
        cnt += bisect_right(cum_B, limit)
        ans = max(ans, cnt)
    print(ans)

if __name__ == "__main__":
    resolve()

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

answer = 0
cost = 0
index_a = 0
for i in range(len(A)):
    if i == len(A) or cost + A[i] > K:
        break
    cost += A[i]
    answer += 1
    index_a = i
index_a -= 1

max_answer = answer
index_b = 0
while (index_b < len(B) and index_a >= 0 and cost > 0):
    if cost + B[index_b] > K:
        cost -= A[index_a]
        index_a -= 1
        answer -= 1
    else:
        cost += B[index_b]
        index_b += 1
        answer += 1
    if max_answer < answer:
        max_answer = answer
print(max_answer)

Submission status: Wrong Answer

Solution code:
in1 = input().split(' ')
N=int(in1[0])
M=int(in1[1])
K=int(in1[2])

inA = input().split(' ')
inB = input().split(' ')

T = 0
Ac=0
Bc=0

while T < K:
  
  if Ac>=N and Bc>=M:
    break
  elif Ac>=N:
    Bn=int(inB[Bc])
    T+=Bn
    Bc+=1
  elif Bc>=M:
    An=int(inA[Ac])
    T+=An
    Ac+=1
  else:
    An=int(inA[Ac])
    Bn=int(inB[Bc])
    if An>Bn:
      T+=An
      Ac+=1
    else:
      T+=Bn
      Bc+=1
  
  

print(Ac+Bc)

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]+A
B = [0]+B
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
j = 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:
in1 = input().split(' ')
N=int(in1[0])
M=int(in1[1])
K=int(in1[2])

inA = input().split(' ')
inB = input().split(' ')

T = 0
Ac=0
Bc=0

while T < K:
  
  if Ac>=N and Bc>=M:
    break
  elif Ac>=N:
    Bn=int(inB[Bc])
    T+=Bn
    Bc+=1
  elif Bc>=M:
    An=int(inA[Ac])
    T+=An
    Ac+=1
  else:
    An=int(inA[Ac])
    Bn=int(inB[Bc])
    if An>Bn:
      T+=An
      Ac+=1
    else:
      T+=Bn
      Bc+=1

print(Ac+Bc)

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冊読んで、残り時間でB机から何冊読めるかを記録していく
lst = [0]*(N+1)

for i in range(N+1):
    time = 0 # 所要時間の初期化
    time = sum(A[0:i]) # A机からi冊読んだときの所要時間
    if time > K:
        break # この時点で制限時間Kを超えていたらB机は無視できる
    else:
        for j in range(M):
            if time + B[j] <= K: # B机のj番目を読んでも所要時間がKを超えないなら読む
                time = time + B[j]
            else: # 読むとKを超えるなら、これまで読んだ冊数を記録する
                lst[i] = i + j
                break

res = max(lst)
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()))

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

ans = 0
best = M-1
for i in range(N):
    if A[i] > K:
        break
    for j in range(best, -1, -1):
        if A[i] + B[j] <= K:
            ans = max(ans, i+j+2)
        elif j == 0 :
            ans = max(ans, i)
print(ans)

Submission status: Wrong Answer

Solution code:
A, B, K = map(int, input().split())
Ai = list(map(int,input().split()))
Bi = list(map(int,input().split()))
count_a = 0
count_b = 0
A_m = Ai[count_a]
B_m = Bi[count_b]
book = []
SUM = sum(Ai) + sum(Bi)

if  SUM <= K:
  print(len(Ai) + len(Bi))
else:
  while K > 0:
    #print(K)
    if A_m > B_m:
      K = K - B_m
      if K >0:
        if count_b < B-1:
          count_b += 1
          B_m = Bi[count_b]
          #print('count_b',count_b)
    else:
      K = K -A_m
      if K >0:
        if count_a < A-1:
          count_a += 1
          A_m = Ai[count_a]
          #print('count_a:',count_a)        

  print(count_a + count_b)

Submission status: Wrong Answer

Solution code:
import sys

input_data = []
input_pointer = 0

output_data = []

def input_scan():
    global input_data
    input_data = sys.stdin.readlines()
    input_data = [x[:-1] for x in input_data]

def next_line():
    global input_pointer
    global input_data
    if input_pointer < len(input_data):
        input_pointer += 1
        return input_data[input_pointer - 1]
    else:
        return ""

def append_output(string):
    global output_data
    output_data.append(string)

def print_output():
    global output_data
    output_data.append("")
    sys.stdout.write("\n".join(output_data))

# problem A
# a = int(input())
# append_output(str(a + a * a + a * a * a))
# print_output()

# problem B
# input_scan()
# s = next_line()
# t = next_line()
# print(sum([1 for x, y in zip(list(s), list(t)) if x != y]))

input_scan()
[n, m, k] = [int(x) for x in next_line().split(" ")]
stack_a = list(reversed([int(x) for x in next_line().split(" ")]))
stack_b = list(reversed([int(x) for x in next_line().split(" ")]))

total_books = 0

while k > 0:
    if len(stack_a) > 0 and len(stack_b) > 0:
        min_val = min(stack_a[-1], stack_b[-1])
        if min_val > k:
            break

        k -= min_val
        total_books += 1
        if min_val == stack_a[-1]:
            stack_a.pop()
            continue

        if min_val == stack_b[-1]:
            stack_b.pop()

    elif len(stack_a) > 0 and stack_a[-1] <= k:
        k -= stack_a[-1]
        stack_a.pop()
        total_books += 1
    elif len(stack_b) > 0 and stack_b[-1] <= k:
        k -= stack_b[-1]
        stack_b.pop()
        total_books += 1
    else:
        break

append_output(str(total_books))
print_output()

Submission status: Wrong Answer

Solution code:
A, B, K = map(int, input().split())
Ai = list(map(int,input().split()))
Bi = list(map(int,input().split()))
count_a = 0
count_b = 0
A_m = Ai[count_a]
B_m = Bi[count_b]
book = []
SUM = sum(Ai) + sum(Bi)

if  SUM <= K:
  print(len(Ai) + len(Bi))
else:
  while K > 0:
    #print(K)
    if A_m > B_m:
      K = K - B_m
      if count_b < B-1:
        count_b += 1
        B_m = Bi[count_b]
        #print('count_b',count_b)
    else:
      K = K -A_m
      if count_a < A-1:
        count_a += 1
        A_m = Ai[count_a]
        #print('count_a:',count_a)        

print(count_a + count_b)

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()))
s = [0]*(n+1)
t = [0]*(m+1)
x = 0
for i in range(n+1):
    s[i] += x + a[i]
    x = s[i]
x = 0
for i in range(n+1):
    if(s[i] >= k):
        x = i
        break
for i in range(m+1):
    t[i] += x + b[i]
    x = t[i]
for i in range(m+1):
    if(t[i] >= k):
        x = max(x,i)
#print(s,t)
while(1):
    f = 0
    for j in range(x-min(x,m),min(x,n)+1):
        #print(j,x-j)
        if(s[j]+t[x-j] <= k):
            #print(j,x-j)
                f = 1
                break
    if(f == 0):
        break
    x += 1
print(x-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()))

ri,sum=-1,0
for i in range(M):
    if sum+B[i]<=K:
        ri=i
        sum+=B[i]
    else :
        break

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

Submission status: Wrong Answer

Solution code:
def main():
    N, M, K = tuple(map(int, input().split()))
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    i_a = 0
    i_b = 0
    s = 0
    while True:
        a = A[i_a] if i_a < N else None
        b = B[i_b] if i_b < M else None

        if not a and not b:
            break

        if (a and not b) or (a and b and a <= b):
            if a > K - s:
                break
            s += a
            i_a += 1
        else:
            if b > K - s:
                break
            s += b
            i_b += 1

    print(i_a + i_b)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    N, M, K = tuple(map(int, input().split()))
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    i_a = 0
    i_b = 0
    s = 0
    c = 0
    while True:
        a = A[i_a] if i_a < N else None
        b = B[i_b] if i_b < M else None

        if not a and not b:
            break

        if a and b and a <= b:
            if a > K - s:
                break
            s += a
            i_a += 1
        elif a and b and a > b:
            if b > K - s:
                break
            s += b
            i_b += 1
        elif a and not b:
            if a > K - s:
                break
            s += a
            i_a += 1
        else:
            if b > K - s:
                break
            s += b
            i_b += 1

    print(i_a + i_b)


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

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

for n in range(len(B)-1):
    B[n+1] += B[n] 

def tansaku(B, tgt):
    if B[0] > tgt:
        return 0
    if B[-1] <= tgt:
        return len(B)

    low = 0
    high = len(B)
    mid = (low+high)//2

    while (high-low) >= 2:
        if B[mid]==tgt:
            break
        elif B[mid] > tgt:
            high = mid
        else:
            low = mid
        mid = (low+high)//2
    
    return mid+1
ans = 0

for a_idx in range(len(A)):
    K_tmp = K - A[a_idx]
    
    if K_tmp < 0:
        break
    elif K_tmp < B[0]:
        ans_tmp = a_idx + 1
    else:
        ans_tmp = a_idx + 1 + tansaku(B, K_tmp)
        
    if ans_tmp > ans:
        ans = ans_tmp
        
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    N, M, K = tuple(map(int, input().split()))
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    s = 0
    c = 0
    while True:
        a = A[0] if len(A) > 0 else None
        b = B[0] if len(B) > 0 else None

        if not a and not b:
            break

        if a and b and a <= b:
            if a > K - s:
                break
            s += a
            c += 1
            del A[0]
        elif a and b and a > b:
            if b > K - s:
                break
            s += b
            c += 1
            del B[0]
        elif a and not b:
            if a > K - s:
                break
            s += a
            c += 1
            del A[0]
        else:
            if b > K - s:
                break
            s += b
            c += 1
            del B[0]

    print(c)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
a=[int(i) for i in input().split()][:n]
b=[int(i) for i in input().split()][:m]
i,j,count=0,0,0
while True:
    if i<n and j<m:
        if a[i]<=b[j]:
            if k>=a[i]:
                count+=1
                k-=a[i]
                i+=1
            else:
                break
        else:
            if k>=b[j]:
                count+=1
                k-=b[j]
                j+=1
            else:
                break
    elif i<n and j>=m:
        if a[i]<=k:
            count+=1
            k-=a[i]
            i+=1
        else:
            break
    elif i>=n and j<m:
        if b[j]<=k:
            count+=1
            k-=b[j]
            j+=1
        else:
            break
    else:
        break                
print(count)

Submission status: Wrong Answer

Solution code:
def main():
    N, M, K = tuple(map(int, input().split()))
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    s = 0
    c = 0
    while True:
        a = A[0] if len(A) > 0 else None
        b = B[0] if len(B) > 0 else None

        if not a and not b:
            break
        if not a:
            t = b, B
        elif not b:
            t = a, A
        elif a <= b:
            t = a, A
        else:
            t = b, B

        if t[0] + s > K:
            break

        s += t[1].pop(0)
        c += 1

    print(c)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

N, M, K = map(int, readline().split())
A = list(map(int, readline().split()))
B = list(map(int, readline().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])

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

Submission status: Wrong Answer

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

N, M, K = map(int, readline().split())
A = list(map(int, readline().split()))
B = list(map(int, readline().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])

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

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()))
temp,temp2=0,0
Sa,Sb=[0]*n,[0]*m
for i in range(n):
    temp+=a[i]
    Sa[i]=temp
for i in range(m):
    temp2+=b[i]
    Sb[i]=temp2
ans,j=0,m-1
for i in range(n):
    if Sa[i]>k: break
    while Sa[i]+Sb[j]>k:
        j-=1
        if j==-1:
            j=0
            break
    ans=max(ans,i+j+2)
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

N,M,K = map(int,input().split())
A = np.array(input().split(),dtype=int)
B = np.array(input().split(),dtype=int)
AA = np.cumsum(A)
BB = np.cumsum(B)
max_mins = 0
max_books = 0
for a in enumerate(AA):
    if a[1] > K:
        break
    for b in enumerate(BB):
        if a[1] + b[1] > K:
            break
        if a[0] + b[0] + 2 > max_books:
            max_books = a[0] + b[0] + 2
print(max_books)

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()))
temp,temp2=0,0
Sa,Sb=[0]*n,[0]*m
for i in range(n):
    temp+=a[i]
    Sa[i]=temp
for i in range(m):
    temp2+=b[i]
    Sb[i]=temp2
temp=0
flag=0
ans=0
for i in range(n-1,-1,-1):
    S=Sa[i]
    if temp==m: break
    if S+Sb[temp]>k: continue
    while S+Sb[temp]<=k:
        temp+=1
        if temp==m:
            flag=1
            break
    t=(i+1)+temp
    if t>ans: ans=t
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    N, M, K = tuple(map(int, input().split()))
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    s = 0
    c = 0
    while len(A) > 0 or len(B) > 0:
        a = A[0] if len(A) > 0 else None
        b = B[0] if len(B) > 0 else None

        if a is None:
            t = b, B
        elif b is None:
            t = a, A
        elif a <= b:
            t = a, A
        else:
            t = b, B

        if t[0] + s > K:
            break

        s += t[1].pop(0)
        c += 1

    print(c)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]

acum = [0] * (n + 1)
bcum = [0] * (m + 1)

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

for j in range(m):
    bcum[j + 1] = bcum[j] + b[j]

max_ans = 0
j = m
for i in range(n):
    if acum[i] > k:
        break
    while acum[i] + bcum[j] > k:
        j -= 1
    max_ans = max(max_ans, i + j)

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()))
temp,temp2=0,0
Sa,Sb=[0]*n,[0]*m
for i in range(n):
    temp+=a[i]
    Sa[i]=temp
for i in range(m):
    temp2+=b[i]
    Sb[i]=temp2
temp=0
flag=0
ans=0
for i in range(n-1,-1,-1):
    S=Sa[i]
    if temp==m or S+Sb[temp]>k: continue
    while S+Sb[temp]<=k:
        temp+=1
        if temp==m:
            flag=1
            break
    t=(i+1)+temp
    if t>ans: ans=t
    #if flag: 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()))
temp,temp2=0,0
Sa,Sb=[0]*n,[0]*m
for i in range(n):
    temp+=a[i]
    Sa[i]=temp
for i in range(m):
    temp2+=b[i]
    Sb[i]=temp2
temp=0
flag=0
ans=0
for i in range(n-1,-1,-1):
    S=Sa[i]
    if S+Sb[temp]>k: continue
    while S+Sb[temp]<=k:
        temp+=1
        if temp==m:
            flag=1
            break
    t=(i+1)+temp
    if t>ans: ans=t
    if flag: 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()))
temp,temp2=0,0
Sa,Sb=[0]*n,[0]*m
for i in range(n):
    temp+=a[i]
    Sa[i]=temp
for i in range(m):
    temp2+=b[i]
    Sb[i]=temp2
temp=0
flag=0
ans=0
for i in range(n-1,-1,-1):
    S=Sa[i]
    if S+Sb[temp]>k: break
    while S+Sb[temp]<=k:
        temp+=1
        if temp==m:
            flag=1
            break
    t=(i+1)+temp
    if t>ans: ans=t
    if flag: break
print(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()))
k = 0
ans = 0

while True:
    if B == []:
        k += A[0]
        A.pop(0)
    elif A == []:
        k += B[0]
        B.pop(0)
    else:
        if A[0] <= B[0]:
            k += A[0]
            A.pop(0)
        elif B[0] <= A[0]:
            k += B[0]
            B.pop(0)
    ans += 1
    if k > K:
        ans -= 1
        break
    elif k == K or (A == [] and B == []):
        break
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy

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

A_time = []
B_time = []

if sum(A) + sum(B) <= K:
    print(len(A) + len(B))
elif K < min(A) and K < min(B):
    print(0)
else:
    #A_res = list(numpy.cumsum(A))
    #B_res = list(numpy.cumsum(B))

    books = []
    max_j = M
    ans = 0

    for i in range(len(A)):
        A_sum = sum(A[0:i+1])
        if A_sum > K:
            break
        res = K - A_sum

        for j in range(max_j, -1, -1):
            B_sum = sum(B[0:j+1])
            #print(A_sum, B_sum, i, j)
            if B_sum < res:
                max_j = j
                ans = max_j + i +2
                break
    print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right

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 j in range(m):
    B.append(B[-1] + b[j])
    
ans = 0
for i in range(n + 1):
    time = A[i]
    b_index = 0
    if time > k:
        continue
    if k  - time > 0:
        b_index = bisect_right(B, k - time)
    ans = max(ans, i + b_index - 1)
print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right

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 j in range(m):
    B.append(B[-1] + b[j])
    
ans = 0
for i in range(n + 1):
    time = A[i]
    b_index = 0
    if time > k:
        break
    if k  - time > 0:
        b_index = bisect_right(B, k - time)
    ans = max(ans, i + b_index - 1)
print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right

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 j in range(m):
    B.append(B[-1] + b[j])
    
ans = 0
for i in range(n):
    time = A[i]
    b_index = 0
    if time > k:
        break
    if k  - time > 0:
        b_index = bisect_right(B, k - time)
    ans = max(ans, i + b_index - 1)
print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right

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 j in range(1, m):
    B.append(B[-1] + b[j])
    
ans = 0
for i in range(n):
    time = A[i]
    b_index = 0
    if time > k:
        break
    if k  - time > 0:
        b_index = bisect_right(B, k - time)
    ans = max(ans, i + b_index - 1)
print(ans)

Submission status: Wrong Answer

Solution code:
# ?
import bisect

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

B_sum = [0] * (M + 1)
for i in range(M):
    B_sum[i+1] = B_sum[i] + B[i] # B_sumのindexが冊数

result = 0
time_count = K
while time_count >= 0:
    for i in A:
        time_count -= i
        tmp = bisect.bisect_right(B_sum, time_count) - 1 + A.index(i)
        result = max(result, tmp)

print(result)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
A = [a[0]]
B = [b[0]]
for i in range(1, n):
    A.append(A[-1] + a[i])
for j in range(1, m):
    B.append(B[-1] + b[j])
    
ans = 0
for i in range(n):
    for j in range(m):
        if A[i] + B[j] <= k:
            ans = max(ans, i + j + 2)
print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right

n, m, k = map(int, input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
A = [a[0]]
B = [b[0]]
for i in range(1, n):
    A.append(A[-1] + a[i])
for j in range(1, m):
    B.append(B[-1] + b[j])
    
ans = 0
for i in range(n):
    time = A[i]
    b_index = 0
    if time > k:
        break
    if k  - time > 0:
        b_index = bisect_right(B, k - time)
    ans = max(ans, i + 1 + b_index)
print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right

n, m, k = map(int, input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
A = [a[0]]
B = [b[0]]
for i in range(1, n):
    A.append(A[-1] + a[i])
for j in range(1, m):
    B.append(B[-1] + b[j])
    
ans = 0
for i in range(n):
    time = A[i]
    b_index = 0
    if time >= k:
        break
    if k  - time >= 0:
        b_index = bisect_right(B, k - time)
    ans = max(ans, i + 1 + b_index)
print(ans)