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

time, count_all, count_a, count_b = 0, 0, 0, 0

while(time < K):
    if(count_all == 0 and (K <= A[0] or K <= B[0])):
        break

    if(len(A) <= len(B)):
        time = time + B[count_b]
        B.pop(0)
        count_all = count_all + 1

    else:
        time = time + A[count_a]
        A.pop(0)
        count_all = count_all + 1

print(count_all)

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=[0]
for i in range(N):
  sumA.append(sumA[-1]+A[i])
sumB=[0]
for i in range(M):
  sumB.append(sumB[-1]+B[i])

ans=0
for i in range(N+1):
  k=K-sumA[i]
  if k<0:
    break
  left=0
  right=len(sumB)-1
  while right>=left:
    mid=(right+left)//2
    if sumB[mid]==k:
      break
    elif sumB[mid]>k:
      right=mid-1
    else:
      left=mid+1
  l=right
  ans=max(ans,i+l)
print(ans)

Submission status: Wrong Answer

Solution code:
import typing

def binary_serch(x:int, b_sum:list):
    l = 0
    r = len(b_sum) - 1
    mid = (l + r + 1) // 2
    res = mid
    while True:
        if x == b_sum[mid]:
            return mid
        elif x < b_sum[mid]:
            res = mid - 1
            r = mid
            mid = (l + r + 1) // 2
        elif b_sum[mid] < x:
            res = mid 
            l = mid
            mid = (l + r + 1) // 2
        if l + 1 == r:
            return res

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
b_sum = [0] * (m + 2)
for i in range(m):
    b_sum[i + 1] = b[i] + b_sum[i]

b_sum[-1] = 10 ** 9 + 1
a = [0] + a
pass_k = 0
book = 0
ans = 0
for i in range(n + 1):
    if pass_k + a[i] <= k:
        pass_k += a[i]
        book = i
        book += binary_serch(k - pass_k, b_sum)
        ans = max(ans, book)

print(ans)

Submission status: Wrong Answer

Solution code:
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
A.reverse()
B.reverse()
l=[0]
for i in range(N+M):
  if len(A)>0 and len(B)>0:
    if A[-1]<=B[-1]:
      l.append(l[-1]+A.pop())
    else:
      l.append(l[-1]+B.pop())
  elif len(A)>0:
    l.append(l[-1]+A.pop())
  else:
    l.append(l[-1]+B.pop())

print(len([x for x in l if x<=K])-1)

Submission status: Wrong Answer

Solution code:
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
A.reverse()
B.reverse()
l=[0]
for i in range(N+M):
  if len(A)>0 and len(B)>0:
    if A[-1]<=B[-1]:
      l.append(l[-1]+A.pop())
    else:
      l.append(l[-1]+B.pop())
  elif len(A)>0:
    l.append(l[-1]+A.pop())
  else:
    l.append(l[-1]+B.pop())

right=len(l)-1
left=0
while right>=left:
  mid=(right+left)//2
  if l[mid]>K:
    right=mid-1
  else:
    left=mid+1

print(right)

Submission status: Wrong Answer

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

Asums = [0] * (N + 1)
for i, a in enumerate(A):
    Asums[i+1] = Asums[i] + a

Bsums = [0] * (M + 1)
for i, b in enumerate(B):
    Bsums[i+1] = Bsums[i] + b

ans = 0
for anum in range(N):
    t = Asums[anum+1]
    if K < t:
        break
    bnum = bisect.bisect_right(Bsums, K - t)
    ans = max(ans, anum + bnum)
print(ans)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
ns = input().split()
ms = input().split()
k_low = False
count = 0
while ns and ms and not k_low:
  if int(ns[0]) < int(ms[0]) and k > int(ns[0]):
    k -= int(ns.pop(0))
    count += 1
  elif int(ns[0]) >= int(ms[0]) and k > int(ms[0]):
    k -= int(ms.pop(0))
    count += 1
  else:
    k_low = True
while ns and not k_low:
  k -= int(ns.pop(0))
  count += 1
while ms and not k_low:
  k -= int(ms.pop(0))
  count += 1
print(count)

Submission status: Wrong Answer

Solution code:
from bisect import bisect
from collections import deque

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

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

indexB = len(B) - 1
results = [0]
for i in range(len(A)):
    time = A[i]
    if time > K:
        break
    enable_for_b = K - time
    results.append(i + bisect(B, enable_for_b))

print(max(results))

Submission status: Wrong Answer

Solution code:
N, M, K = input().split()
a_timelist = input().split()
b_timelist = input().split()
N, M, K = int(N), int(M), int(K)
a_timelist = [int(x) for x in a_timelist]
b_timelist = [int(x) for x in b_timelist]
counta = len(a_timelist)
countb = len(b_timelist)
counter = 0
time = 0
if a_timelist[0] > K and b_timelist[0] > K:
  print(0)
  exit()
while time <= K:
#  print(a_timelist)
#  print("あ")
#  print(b_timelist)
  if a_timelist == [] and b_timelist == []:
    print(counta + countb)
    exit()
  if (a_timelist == [] and b_timelist != []) or (b_timelist == [] and a_timelist != []):
    if (b_timelist == [] and a_timelist != []):
          time += a_timelist[0]
          counter += 1
          del a_timelist[0]
    elif (a_timelist == [] and b_timelist != []):
          time += b_timelist[0]
          counter += 1
          del b_timelist[0]
  elif a_timelist[0] >= b_timelist[0]:
    time += a_timelist[0]
    counter += 1
    del a_timelist[0]
  elif a_timelist[0] < b_timelist[0]:
    time += b_timelist[0]
    counter += 1
    del b_timelist[0]
print(counter)

Submission status: Wrong Answer

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

a.append(10**10)
b.append(10**11)

i = 0
j = 0
t = 0
cnt = 0
while t+a[i] <= k or t+b[j] <= k:
  if a[i] < b[j]:
    t += a[i]
    i += 1
    cnt += 1
  if a[i] > b[j]:
    t += b[j]
    j += 1
    cnt += 1
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()))

a.append(10**10)
b.append(10**11)

i = 0
j = 0
t = 0
cnt = 0
while t+a[i] <= k or t+b[j] <= k:
  if a[i] < b[j]:
    t += a[i]
    i += 1
    cnt += 1
  else:
    t += b[j]
    j += 1
    cnt += 1
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()))

a.append(10**10)
b.append(10**11)

print(n,m,k,a,b)

i = 0
j = 0
t = 0
cnt = 0
while t+a[i] <= k or t+b[j] <= k:
  if a[i] < b[j]:
    t += a[i]
    i += 1
    cnt += 1
  else:
    t += b[j]
    j += 1
    cnt += 1
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()))

a.append(10**10)
b.append(10**10)
i = 0
j = 0
t = 0
cnt = 0
while t+a[i] <= k or t+b[j] <= k:
  if a[i] < b[j]:
    t += a[i]
    i += 1
    cnt += 1
  else:
    t += b[j]
    j += 1
    cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
INF=10**18
a=list(map(int,input().split()))+[INF]*max(0,m-n)
b=list(map(int,input().split()))+[INF]*max(0,n-m)
i,j=0,0
while k>0:
  if a[i]<=b[j] and k>=a[i]:
    k-=a[i]
    i+=1
  elif a[i]>b[j] and k>=b[j]:
    k-=b[j]
    j+=1
  else:break
  if i==max(n,m) or j==max(n,m):break
print(i+j)

Submission status: Wrong Answer

Solution code:
from bisect import bisect
from collections import deque

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

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

indexB = len(B) - 1
results = [0]
for i in range(len(A)):
    time = A[i]
    if time > K:
        break
    enable_for_b = K - time
    results.append(i+1 + bisect(B, enable_for_b))

print(max(results))

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

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

indexB = len(B) - 1
best = 0
for i in range(len(A)):
    time = A[i]
    if time > K:
        break
    while(indexB >= 0 and time + B[indexB] > K):
        indexB -= 1
    count = i+1 + indexB+1
    if (best < count):
        best = count
print(best)

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

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

indexB = len(B) - 1
best = 0
for i in range(len(A)):
    time = A[i]
    if time > K:
        break
    else:
        while(indexB >= 0 and time + B[indexB] > K):
            indexB -= 1
        count = i+1 + indexB+1
    if (best < count):
        best = count
print(best)

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

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

indexB = len(B) - 1
best = 0
for i in range(len(A)):
    time = A[i]
    if time > K:
        break
    else:
        while(indexB >= 0 and time + B[indexB] > K):
            indexB -= 1
        count = i+1 + indexB+1
        if indexB < len(B)-1:
            indexB += 1
    if (best < count):
        best = count
print(best)

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

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

indexB = -1
best = 0
for i in range(len(A)):
    time = A[i]
    if time > K:
        break
    else:
        while(indexB+1 < len(B) and time + B[indexB+1] <= K):
            indexB += 1
            time += B[indexB]
        count = i+1 + indexB+1
    if (best < count):
        best = count
print(best)

Submission status: Wrong Answer

Solution code:
n,m,k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.append(10**10 + 1)
b.append(10**10 + 1)
acount = 0
bcount = 0
t = 0
while True:
	if acount == n and bcount == m:
		break
	elif b[bcount] >= a[acount]:
		t += a[acount]
		acount += 1
		if t > k:
			break
	else:
		t += b[bcount]
		bcount += 1
		if t > k:
			break
if acount + bcount == n + m and t < k:
	print(acount+bcount)
else:
	print(acount+bcount-1)

Submission status: Wrong Answer

Solution code:
n,m,k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.append(10**10+1)
b.append(10**10+1)
acount = 0
bcount = 0
t = 0
while True:
	if acount == n and bcount == m:
		break
	elif b[bcount] >= a[acount]:
		t += a[acount]
		acount += 1
		if t > k:
			break
	else:
		t += b[bcount]
		bcount += 1
		if t > k:
			break
if acount + bcount == n + m:
	print(acount+bcount)
else:
	print(acount+bcount-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()))

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

if k < a[0] and k < b[0]:
    print(0)
    exit()

ans = 0
for i in range(n):
    while k - sum(a[:i]) < sum(b[:m]):
        m -= 1

    ans = max(ans, i+m)


print(ans)

Submission status: Wrong Answer

Solution code:
info = list(map(int, input().split()))
N = info[0]
M = info[1]
K = info[2]
L = max(N, M)

A_books = list(map(int, input().split()))
B_books = list(map(int, input().split()))


if len(A_books) < M:
    for i in range(M - N):
        A_books.append(float("inf"))

if len(B_books) < N:
    for i in range(N - M):
        B_books.append(float("inf"))


min = 0
count = 0
i = 0
j = 0

while (min <= K) and (i < L) and (j < L):
    if A_books[i] < B_books[j]:
        min += A_books[i]
        if min <= K:
            count += 1
        i += 1
    else:
        min += B_books[j]
        if min <= K:
            count += 1
        j += 1


print(count)

Submission status: Wrong Answer

Solution code:
def getIntList(strList):
  return list(map(lambda x: int(x), strList))

N, M, K = getIntList(input().split(" "))
A = getIntList(input().split(" "))
B = getIntList(input().split(" "))

TA = 0
T = [0]
cnt = [] # idx = n of B books

for i in range(len(A)):
  TA += A[i]
  if TA <= K:
    T.append(TA)
  else:
    break

cnt.append(len(T) - 1)

for j in range(len(B)):
  print(T)
  print(cnt)
  T = list(filter(lambda t: t<= K, list(map(lambda t: t + B[j], T))))
  cnt.append(len(T) - 1)
  if len(T) <= 0:
    break

for k in range(len(cnt)):
  cnt[k] += k

print(max(cnt))

Submission status: Wrong Answer

Solution code:
def getIntList(strList):
  return list(map(lambda x: int(x), strList))

N, M, K = getIntList(input().split(" "))
A = getIntList(input().split(" "))
B = getIntList(input().split(" "))

la = len(A)
lb = len(B)
i = 0
j = 0

T = 0
while T < K:
  if i >= len(A) and j >= len(B):
    break
  elif i >= len(A):
    T += B[j]
    if T <= K:
      j += 1
  elif j >= len(B):
    T += A[i]
    if T <= K:
      i += 1
  else:
    if A[i] >= B[j]:
      T += B[j]
      if T <= K:
        j += 1
    elif A[i] < B[j]:
      T += A[i]
      if T <= K:
        i += 1

print(i + j)

Submission status: Wrong Answer

Solution code:
number=list(map(int,input().split()))
N,M,K=number[0],number[1],number[2]
A=list(map(int,input().split()))
B=list(map(int,input().split()))
a=[0]
b=[0]
for i in range(1,len(A)+1):
    tmp=a[i-1]+A[i-1]
    a.append(tmp)
    
for i in range(1,len(B)+1):
    tmp=b[i-1]+B[i-1]
    b.append(tmp)

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

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque

N, M, K = map(int, input().split())
A = deque(list(map(int, input().split())))
B = deque(list(map(int, input().split())))
time = 0
count = 0
nextA = A.popleft()
nextB = B.popleft()

while(True):
    if nextA == None and nextB == None:
        break
    if nextA == None:
        do = "popB"
    elif nextB == None:
        do = "popA"
    elif nextA < nextB:
        do = "popA"
    else:
        do = "popB"
    
    if do == "popA":
        count += 1
        time += nextA
        if len(A) == 0:
            nextA = None
        else:
            nextA = A.popleft()
    else:
        count += 1
        time += nextB
        if len(B) == 0:
            nextB = None
        else:
            nextB = B.popleft()
    if time == K:
        break
    if time > K:
        count -= 1
        break

print(count)

Submission status: Wrong Answer

Solution code:
from collections import deque

N, M, K = map(int, input().split())
A = deque(list(map(int, input().split())))
B = deque(list(map(int, input().split())))
time = 0
count = 0
nextA = A.popleft()
nextB = B.popleft()

while(True):
    if nextA == None and nextB == None:
        break
    if nextA == None:
        do = "popB"
    elif nextB == None:
        do = "popA"
    elif nextA < nextB:
        do = "popA"
    else:
        do = "popB"
    
    if do == "popA":
        count += 1
        time += nextA
        if len(A) == 0:
            nextA = None
        else:
            nextA = A.popleft()
    else:
        count += 1
        time += nextB
        if len(B) == 0:
            nextB = None
        else:
            nextB = B.popleft()
    if time > K:
        count -= 1
        break

print(count)

Submission status: Wrong Answer

Solution code:
# import itertools
# import math
# import sys
import numpy as np

# N = int(input())
# S = input()
# n, *a = map(int, open(0))
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
# S = input()

# d = sorted(d.items(), key=lambda x:x[0]) # keyでsort
# all_cases = list(itertools.permutations(P))
# a = list(itertools.combinations_with_replacement([i for i in range(1, M + 1)], N))
# print(a[0][0])
# print(conditions[0])

A = np.array(A)
B = np.array(B)

cum_A = np.cumsum(A)
cum_B = np.cumsum(B)

j = M - 1
max_num = 0
for i in range(N):
    while(True):
        # j -= 1
        if j < 0:
            break
        minute = cum_A[i] + cum_B[j]
        if minute <= K:
            if (i + 1) + (j + 1) > max_num:
                max_num = (i + 1) + (j + 1)
            break
        j -= 1


print(max_num)

Submission status: Wrong Answer

Solution code:
import numpy as np
n,m,k = list(map(int, input().split()))
a_list = np.array(input().split()).astype(int)
b_list = np.array(input().split()).astype(int)
a_sum =[0]
b_sum=[0]
for i in range(n):
    a_sum.append(a_sum[-1]+ a_list[i])
for i in range(m):
    b_sum.append(b_sum[-1] + b_list[i])
#print(a_sum, b_sum)
total = 0

for i in range(n+1):
    num = 0
    if a_sum[i] > k:
        break
    while (k - a_sum[i]) >= b_sum[num]:
        num +=1
        #print(i, num)
        if num == m:
            break
    total = max(i+num, total)
    
    
print(total)

Submission status: Wrong Answer

Solution code:
import numpy as np
n,m,k = list(map(int, input().split()))
a_list = np.array(input().split()).astype(int)
b_list = np.array(input().split()).astype(int)
ans_list=[]
for i in range(n):
    for l in range(m):
        if sum(a_list[:i]) + sum(b_list[:l]) <= k:
            ans_list.append(i+l)
            

print(max(ans_list))

Submission status: Wrong Answer

Solution code:
import numpy as np
param_list = np.array(input().split()).astype(int)
a_list = np.array(input().split()).astype(int)
b_list = np.array(input().split()).astype(int)
ans=0
for i in range(param_list[0]+1):
    for l in range(param_list[1]+1):
        a = sum(a_list[:i]) + sum(b_list[:l])
        b= 0
        if  a <= param_list[2]:
            if b <= i+l:
                b = i+l
            
print(b)

Submission status: Wrong Answer

Solution code:
import numpy as np
param_list = np.array(input().split()).astype(int)
a_list = np.array(input().split()).astype(int)
b_list = np.array(input().split()).astype(int)
ans=0
for i in range(param_list[0]):
    for l in range(param_list[1]):
        a = sum(a_list[:i]) + sum(b_list[:l])
        b= 0
        if  a <= param_list[2]:
            if b <= i+l:
                b = i+l
            
print(b)

Submission status: Wrong Answer

Solution code:
import numpy as np

n,m,k = list(map(int, input().split()))
a_list = np.array(input().split()).astype(int)
b_list = np.array(input().split()).astype(int)
ans=0
b =0

for i in range(n):
    for l in range(m):
        a = sum(a_list[:i]) + sum(b_list[:l])
        if  a <= k:
            if b <= i+l:
                b = i+l
            
print(b)

Submission status: Wrong Answer

Solution code:
n, m,k = list(map(int, input().split()))
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
count = 0
for i in range(n + m):
    #print(k)
    if len(a_list) >= 1 and len(b_list) >= 1:
        if a_list[0] >= b_list[0]: 
            k -= b_list.pop(0)
        else:
            k -= a_list.pop(0)
    elif len(a_list) == 0:
        k -= b_list.pop(0)
    else:
        k -= a_list.pop(0)
        
    if k >= 0:
        count += 1
    else:
        break
            
            
        
print(count)

Submission status: Wrong Answer

Solution code:
n, m,k = list(map(int, input().split()))
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
count = 0
for i in range(n + m):
    #print(k)
    if len(a_list) >= 1 and len(b_list) >= 1:
        if a_list[0] >= b_list[0]: 
            k -= a_list.pop(0)
        else:
            k -= b_list.pop(0)
    elif len(a_list) == 0:
        k -= b_list.pop(0)
    else:
        k -= a_list.pop(0)
        
    if k > 0:
        count += 1
    else:
        break
if count == n+m:
    print(count)
elif count == 0:
    print(count)
else: print(count +1)

Submission status: Wrong Answer

Solution code:
n, m,k = list(map(int, input().split()))
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
count = 0
for i in range(n + m):
    #print(k)
    if len(a_list) >= 1 and len(b_list) >= 1:
        if a_list[0] >= b_list[0]: 
            k -= a_list.pop(0)
    elif len(a_list) == 0:
        k -= b_list.pop(0)
    else:
        k -= a_list.pop(0)
        
    if k > 0:
        count += 1
    else:
        break
if count == n+m:
    print(count)
else:
    print(count+1)

Submission status: Wrong Answer

Solution code:
from collections import deque
h, w, k = map(int,input().split())
a = deque(map(int,input().split()))
b = deque(map(int,input().split()))

ans = 0
total = 0
while total <= k:
  if len(a) != 0 and len(b) != 0:
    if a[0] < b[0]:
      total += a.popleft()
    else:
      total += b.popleft()
    ans += 1
  elif len(a) == 0 and len(b) == 0:
    break
  elif len(a) == 0:
    total += b.popleft()
    ans += 1
  else:
    total += a.popleft()
    ans += 1
  
if total > k:
  print(ans - 1)
else:
  print(ans)

Submission status: Wrong Answer

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

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

ans = 0
temp_a = {}
temp_b = {}

for i_a in range(n+1):
  temp_a[i_a] = sum(a[0:i_a])
for i_b in range(m+1):
  temp_b[i_b] = sum(b[0:i_b])
  
temp_a = sorted(temp_a.items(), key=lambda x:x[1], reverse=True)
temp_b = sorted(temp_b.items(), key=lambda x:x[1], reverse=True)
ans = {}

for item_a in temp_a:
  for item_b in temp_b:
    if item_a[1] + item_b[1] > k:
      continue
    else:
      ans[len(ans)] = item_a[1] + item_b[1]
      break
ans = max(ans.values())
print(ans)

Submission status: Wrong Answer

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

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

ans = 0

for i_a in range(n):
  lst_book = []
  lst_book.extend(a[0:i_a])
  for i_b in range(m):
    lst_book.extend(b[0:i_b])
    if sum(lst_book) <= k:
      ans = max(ans, len(lst_book))

print(ans)

Submission status: Wrong Answer

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

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

a.extend(b)
a.sort()

add = 0
cnt = 0
for item in a:
  if add > k:
    break
  add += item
  cnt += 1
print(cnt)

Submission status: Wrong Answer

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

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

a.extend(b)
a.sort()

add = 0
cnt = 0
for item in a:
  if add >= k:
    break
  add += item
  cnt += 1
print(cnt)

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(2,n):
    A[i] += A[i-1]
for i in range(1,m):
    B[i] += B[i-1]
j = m
ans = 0
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 = list(map(int, input().split()))
b_list = list(map(int, input().split()))


min = 0
i = 0
j = 0
ans = 0

while min < k:
    if len(a_list) <= i and len(b_list) <= j:
        break
    elif len(a_list) <= i:
        min = min + b_list[j]
        j = j + 1
    elif len(b_list) <= j:
        min = min + a_list[i]
        i = i + 1
    elif a_list[i] <= b_list[j]:
        min = min + a_list[i]
        i = i + 1
    else:
        min = min + b_list[j]
        j = j + 1
    if min > k:
        break
    ans = ans + 1
print(ans)

Submission status: Wrong Answer

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

def check_(lis, num, ti):
    ans = 0
    re_lis = []
    for i in range(num):
        ans +=  lis[i]
        if ans >= ti:
            break
        else:
            re_lis.append(ans)
    return re_lis

a = [0] + check_(a, m, k)
a.reverse()
b = [0] + check_(b, n, k)

ans = 0
for i in range(len(a)):
    flag = 0
    j = 0
    while flag == 0:
        p = len(a) - i -1 + j

        if j == len(b)-1 or a[i] + b[j] > k:
            flag = 1
        if a[i] + b[j] <= k and p > ans:
            ans = p 
        j += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
 
#入力
N,M,K = (int(x) for x in input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
 
#A総和のリストの作成
A_sum = [0]*N
A_sum[0]=A[0]
for i in range(N-1):
  A_sum[i+1]=A_sum[i]+A[i+1]
 
#B総和のリストの作成
B_sum = [0]*M
B_sum[0]=B[0]
for i in range(M-1):
  B_sum[i+1]=B_sum[i]+B[i+1]
 
SUM = []
 
#計算の開始
for j in range(N):
  remain = K-A_sum[j]
  if remain>=0:
    B_number=bisect.bisect(B_sum,remain)
    if B_number==0:
      SUM.append(j+1)
    else:
      SUM.append(j+1+B_number)
  else:
    SUM.append(0)
 
print(max(SUM))

Submission status: Wrong Answer

Solution code:
#Aの冊数を固定し0,1,2,...
#Aの冊数のとき,Bを何冊読めるかを2分探索で求める
#Bについて上から時間の和のリストを出しておき残り時間で読める冊数を求める

import bisect

#入力
N,M,K = (int(x) for x in input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

#A総和のリストの作成
A_sum = [0]*N
A_sum[0]=A[0]
for i in range(N-1):
  A_sum[i+1]=A_sum[i]+A[i+1]

#B総和のリストの作成
B_sum = [0]*M
B_sum[0]=B[0]
for i in range(M-1):
  B_sum[i+1]=B_sum[i]+B[i+1]

SUM = []

#計算の開始
for j in range(N):
  remain = K-A_sum[j]
  if remain>=0:
    B_number=bisect.bisect(B_sum,remain)
    if B_number==0:
      SUM.append(j+1)
    else:
      SUM.append(j+1+B_number)
  else:
    SUM.append(0)

print(max(SUM))

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 = deque(A)
B = deque(B)

time = 0
ctr = 0
while time < k:
    if len(A)>0 and len(B)>0:
        if A[0] < B[0]:
            time += A.popleft()
        else:
            time += B.popleft()
    elif len(A)>0:
        time += A.popleft()
    elif len(B)>0:
        time += B.popleft()
    else:
        break
    ctr+=1

if time > k:
    ctr-=1
print(ctr)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

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

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

INF = float('inf')
# dp[n][m] represents total time took to read top n book from A and top m book from B
dp = [[INF] * (M+1) for _ in range(N+1)]
dp[0][0] = 0

count = 0
for i in range(N):
    dp[i+1][0] = dp[i][0] + A[i]
    if dp[i+1][0] > K:
        break
    else:
        count = i+1

for i in range(N+1):
    for j in range(M):
        dp[i][j+1] = dp[i][j] + B[j]
        if dp[i][j+1] > K:
            break
        else:
            count = i + j + 1

print(count)

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_list = a + b
time_list = np.sort(time_list)
cum_times = np.cumsum(time_list)
print(int((cum_times <= K).sum()))

Submission status: Wrong Answer

Solution code:
import bisect

#入力
N,M,K = (int(x) for x in input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

#B総和のリストの作成
B_sum = [0]*M
B_sum[0]=B[0]
for i in range(M-1):
  B_sum[i+1]=B_sum[i]+B[i+1]

SUM = []

#計算の開始
for j in range(N):
  A_sum=0
  for k in range(j+1):
    A_sum+=A[k]
  remain = K-A_sum

  if remain>=0:
    B_number=bisect.bisect(B_sum,remain)
    if B_number==0:
      SUM.append(j+1)
    else:
      SUM.append(j+1+B_number)
  else:
    SUM.append(0)

print(max(SUM))

Submission status: Wrong Answer

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

time = 0
count = -1

while time <= K:
    if A[0] >= B[0]:
        time += B[0]
        B.pop(0)
        count += 1
    else:
        time += A[0]
        A.pop(0)
        count += 1

print(count)

Submission status: Wrong Answer

Solution code:
import bisect
N,M,K = map(int,input().split())

a = list(map(int,input().split()))
b = list(map(int,input().split()))
A = [0]
B = [0]
ans = 0
for i in range(N):
  if A[i]+a[i] <=K:
    A.append(A[i]+a[i])
  else:
    break

for i in range(M):
  if B[i]+b[i] <=K:
    B.append(B[i]+b[i])
  else:
    break

if len(A)==1 and len(B)==1:
  print(0)
  exit()

for i in range(len(A)):
  if K -A[i]>=0:
    j = bisect.bisect_left(B,K-A[i])
    if ans <=i+j:
      ans=max(ans,i+j)
      #print(i,j)
    else:
      break
    
for i in range(len(B)):
  if K -B[i]>=0:
    j = bisect.bisect_left(A,K-B[i])
    if ans <=i+j:
      ans=max(ans,i+j)
      #print(i,j)
    else:
      break

print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
N,M,K = map(int,input().split())

a = list(map(int,input().split()))
b = list(map(int,input().split()))
A = [0]
B = [0]
ans = 0
for i in range(N):
  if A[i]+a[i] <=K:
    A.append(A[i]+a[i])
  else:
    break

for i in range(M):
  if B[i]+b[i] <=K:
    B.append(B[i]+b[i])
  else:
    break

if len(A)==1 and len(B)==1:
  print(0)
  exit()
for i in range(len(A)):
  j = bisect.bisect(B,K-A[i]-0.1)
  if ans <i+j:
    ans=i+j
    #print(i,j)
print(ans)