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=[int(x) for x in input().split()]
b=[int(x) for x in input().split()]
ar=[a[0]]
br=[b[0]]
for i in range(1,n):
  ar.append(ar[i-1]+a[i])
for i in range(1,m):
  br.append(br[i-1]+b[i])

ans=0
j=0
cnt=0

for i in range(n):
  now=ar[i]
  cnt=i+1
  nokori=k-now

  while(br[j]<=nokori):
    if j<m-1:
      j+=1
      ans=max(ans,cnt+j+1)
    else:
      ans=max(ans,cnt+j+1)
      break
    
print(ans)

Submission status: Wrong Answer

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


sum_a = [0]
for i in range(n):
    sum_a.append(sum_a[i] + a[i])

sum_b = [0]
for i in range(m):
    sum_b.append(sum_b[i] + b[i])


a_i = 0
b_i = 0
for i in range(n+1):
    if sum_a[i] > k:
        break
    else:
        a_i = i

for i in range(m+1):
    if sum_a[a_i] + sum_b[i] > k:
        break
    else:
        b_i = i


ans = a_i + b_i
for i in range(a_i, 0, -1):
    for j in range(b_i, m+1):
        if sum_a[i] + sum_b[j] > k:
            b_i = j - 1
            break
        else:
            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())) 


sum_a = [0]
for i in range(n):
    sum_a.append(sum_a[i] + a[i])

sum_b = [0]
for i in range(m):
    sum_b.append(sum_b[i] + b[i])


a_i = 0
b_i = 0
for i in range(n+1):
    if sum_a[i] > k:
        break
    else:
        a_i = i

for i in range(m+1):
    if sum_a[a_i] + sum_b[i] > k:
        break
    else:
        b_i = i


ans = a_i + b_i
for i in range(a_i, 0, -1):
    for j in range(b_i, m+1):
        if sum_a[i] + sum_b[j] > k:
            b_i = i - 1
            break
        else:
            ans = max(ans, i+j)

print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect
from itertools import accumulate
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a = list(accumulate(a))
b = list(accumulate(b))
ans = 0
for i in range(n):
    if a[i] > k:
        break
    ans = max(ans, i+1+bisect(b, k-a[i]))
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())) 


sum_a = [0]
for i in range(n):
    sum_a.append(sum_a[i]+a[i])

sum_b = [0]
for i in range(m):
    sum_b.append(sum_b[i]+b[i])


a_i = 0
b_i = 0
for i in range(n+1):
    if sum_a[i] > k:
        break
    else:
        a_i = i

for i in range(m+1):
    if sum_a[a_i] + sum_b[i] > k:
        break
    else:
        b_i = i


ans = a_i + b_i
for i in range(a_i, 0, -1):
    for j in range(b_i, m+1):
        if sum_a[i] + sum_b[j] > k:
            break
        else:
            ans = max(ans, i+j)

print(ans)

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

total = 0
Asum = sum(A)
nA = len(A)
Bsum = 0
ans = 0
for nB in range(len(B) + 1):
    if nA <= 0:
        break
    if nB != 0:
        Bsum += B[nB-1]
    while Asum + Bsum > K:
        nA -= 1
        Asum -= A[nA]
    ans = max(nA + nB, ans)

print(ans)

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

total = 0
maxb = 0
for i in range(N):
    if total + A[i] <= K:
        total += A[i]
        maxb += 1
    else:
        break

i = maxb - 1
for j in range(M):
    while i >= 0 or total + B[j] <= K:
        if total + B[j] <= K:
            total += B[j]
            if i < 0:
                if maxb < j + 1:
                    maxb = j + 1
            else:
                if maxb < i + j + 2:
                    maxb = i + j + 2
            break
        else:
            total -= A[i]
            i -= 1

print(maxb)

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

total = 0
maxb = 0
for i in range(N):
    if total + A[i] <= K:
        total += A[i]
        maxb += 1
    else:
        break

i = maxb - 1
for j in range(M):
    while i >= 0 or total + B[j] <= K:
        if total + B[j] <= K:
            total += B[j]
            if maxb < i + j + 2:
                maxb = i + j + 2
            break
        else:
            total -= A[i]
            i -= 1
    if i == -1:
        break

print(maxb)

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

total = 0
maxb = 0
for i in range(N):
    if total + A[i] <= K:
        total += A[i]
        maxb += 1
    else:
        break

i = maxb - 1
for j in range(M):
    if i == -1:
        break
    while i >= 0:
        if total + B[j] <= K:
            total += B[j]
            if maxb < i + j + 2:
                maxb = i + j + 2
            break
        else:
            total -= A[i]
            i -= 1

print(maxb)

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

total = 0
maxb = 0
for i in range(N):
    if total + A[i] <= K:
        total += A[i]
        maxb += 1
    else:
        break

i = maxb - 1
for j in range(M):

    if total + B[j] <= K:
        total += B[j]
    else:
        if i == -1:
            break
        total -= A[i]
        i -= 1
        j -= 1

    if maxb < i + j + 2:
        maxb = i + j + 2
print(maxb)

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

i, j = 0, 0
maxb = 0
time = 0
while True:
    if i < N and j < M:
        if A[i] < B[j]:
            time += A[i]
            i += 1
        else:
            time += B[j]
            j += 1
    elif i < N:
        time += A[i]
        i += 1
    elif j < M:
        time += B[j]
        j += 1
    else:
        break
    if time <= K:
        maxb += 1
    else:
        break
print(maxb)

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()))
cnt1 = 0
cnt2 = 0
  
while cnt1 <= k:
  if a == [] and b == []:
    cnt2 += 1
    break
  elif a != [] and b == []:
    cnt1 += a[0]
    cnt2 += 1
    del a[0]
  elif a == [] and b != []:
    cnt1 += b[0]
    cnt2 += 1
    del b[0] 
  elif a[0] <= b[0]:
    cnt1 += a[0]
    cnt2 += 1
    del a[0]
  elif a[0] > b[0]:
    cnt1 += b[0]
    cnt2 += 1
    del b[0]
  
print(cnt2-1)

Submission status: Wrong Answer

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

A_sum = [0]
B_sum = [0]
A_now = 0
B_now = 0
for i in range(N):
    A_now = A[i] + A_now
    A_sum.append(A_now)
for i in range(M):
    B_now = B[i] + B_now
    B_sum.append(B_now)


ans = 0
for i in range(N+1):
    book_count = i
    remain_time = K - A_sum[i]

    ok = 0
    ng = M

    if remain_time >= B_sum[M]:
        ans = book_count + M

    while ng - ok > 1:
        mid = (ok+ng)//2
        if remain_time >= B_sum[mid]:
            ok = mid
        else:
            ng = mid

    book_count += ok
    if remain_time > 0:
        if book_count > ans:
            ans = book_count
#            print(mid,remain_time,B_sum[ok])                                                       

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools
import collections
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()

NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()

def main():
    N, M, K = NMI()
    A = NLI()
    B = NLI()
    
    cumsum_A = [0 for _ in range(len(A)+1)]
    cumsum_B = [0 for _ in range(len(B)+1)]    
    
    cnt = 0
    
    for n in range(N):
        cnt += A[n]
        cumsum_A[n+1] = cnt
        
    cnt = 0
    
    for m in range(M):
        cnt += B[m]
        cumsum_B[m+1] = cnt
    

    
    ans = 0
    
    for n in range(N+1):
        remain_K = K - cumsum_A[n]
        if remain_K < 0:
            break
        else:
            for m in range(M,-1,-1):
                if cumsum_B[m]> remain_K:
                    continue
                else:
                    print(ans,n,m)
                    ans = max(ans,n+m)
                break
    
    print(ans)
            
    


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

cnt = 0
time = 0

while time <= k:
    if len(a) != 0 and len(b) != 0:
        if a[0] <= b[0]:
            cnt += 1
            time += a[0]
            a.remove(a[0])
        elif time + b[0] <= k:
            cnt += 1
            time += b[0]
            b.remove(b[0])
    elif len(a) != 0:
        cnt +=1
        time += a[0]
        a.remove(a[0])
    elif len(b) != 0:
        cnt += 1
        time += b[0]
        b.remove(b[0])
    else:
        cnt += 1
        break
    
print(cnt-1)

Submission status: Wrong Answer

Solution code:
# ABC C-Tsundoku
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

ans = 0
flag = False
for i in range(n+1):
    if flag == True:
        break
    for j in range(m+1):
        if sum(a[:i])+sum(b[:j])<=k and ans < i+j:
            ans = i+j
            flag = True
            break
print(ans)

Submission status: Wrong Answer

Solution code:
# ABC C-Tsundoku
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

ans = 0
if sum(a)+sum(b) <= k:
    ans = n+m
    print(ans)
else:
    flag = False
    for i in range(n+1):
        if flag == True:
            break
        for j in range(m+1):
            if sum(a[:i])+sum(b[:j])<=k and ans < i+j:
                ans = i+j
                flag = True
                break
    print(ans)

Submission status: Wrong Answer

Solution code:
# ABC C-Tsundoku
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

ans = 0
if sum(a)+sum(b) <= k:
    ans = n+m
    print(ans)
else:
    flag = False
    for i in range(n):
        if flag == True:
            break
        for j in range(m):
            if sum(a[:i])+sum(b[:j])>k and ans < i+j:
                ans = i+j
                flag = True
                break
    print(ans)

Submission status: Wrong Answer

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

a, b = [0], [0]
for i in range(N):
    a.append(a[i] + A[i])
for i in range(M):
    b.append(b[i] + B[i])
print(a,b)

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_ls = [0] + list(map(int, input().split(' ')))
for i in range(N):
    A_ls[i + 1] += A_ls[i]
B_ls = [0] + list(map(int, input().split(' ')))
for i in range(M):
    B_ls[i + 1] = B_ls[i]

b_cnt, rst = M, 0 
for a_cnt in range(N + 1):
    if A_ls[a_cnt] > K:
        break
    while A_ls[a_cnt] + B_ls[b_cnt] > K and b_cnt >= 0:
        b_cnt -= 1
    rst = max(rst, a_cnt + b_cnt)
print(rst)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
lst1=list(map(int,input().split()))
lst2=list(map(int,input().split()))
c=min(n,m)
count=0
flag=0
x=[]
i=0
while i<(n+m):
    if len(lst1)==0:
        for j in range(len(lst2)):
            x.append(lst2[j])
        break
        # i=0
    elif len(lst2)==0:
        for j in range(len(lst1)):
            x.append(lst1[j])
        break
    elif lst1[i]<lst2[i]:
        x.append(lst1[i])
        lst1.remove(lst1[i])
        # print(lst1)
        i=0
    
    elif lst1[i]>=lst2[i]:
        x.append(lst2[i])
        lst2.remove(lst2[i])
        # print(lst2)
        i=0
    elif len(lst1)==0 and len(lst2)==0:
        break
for b in range(len(x)):
    if x[b]<=k:
        k-=x[b]
        if k<0:
            break
        count+=1
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())))

total_time = 0
time = 0
count = 0
for _ in range(N + M):
    if len(A) > 0 and len(B) > 0:
        if A[0] <= B[0]:
            time = A.popleft()
        else:
            time = B.popleft()
    elif len(A) == 0 and len(B) > 0:
        time = B.popleft()
    elif len(A) > 0 and len(B) == 0:
        time = A.popleft()
    else:
        break
    
    if total_time + time > K:
        break
    else:
        total_time += time
        count += 1
        
print(count)

Submission status: Wrong Answer

Solution code:
N,M,K=input().split(' ')
A=input().split(' ')
B=input().split(' ')

time=0
count=0
flag=0

for i in range(len(A)+len(B)):
  if(int(A[0])<int(B[0])):
    time+=int(A[0])
    if(len(A)>1):
      A=A[1:]
    else:
      A[0]=1000000000
  else:
    time+=int(B[0])
    if(len(B)>1):
      B=B[1:]
    else:
      B[0]=1000000000
  count+=1
  if(A[0]==1000000000 and B[0] ==1000000000):
    break
  #print(time)
  if(time>int(K)):
    print(count-1)
    flag=1
    break
if(flag==0):
	print(count)

Submission status: Wrong Answer

Solution code:
N,M,K=input().split(' ')
A=input().split(' ')
B=input().split(' ')

time=0
count=0
flag=0

for i in range(len(A)+len(B)):
  if(int(A[0])<int(B[0])):
    time+=int(A[0])
    if(len(A)>1):
      A=A[1:]
    else:
      A[0]=10000
  else:
    time+=int(B[0])
    if(len(B)>1):
      B=B[1:]
    else:
      B[0]=10000
  count+=1
  #print(time)
  if(time>int(K)):
    print(count-1)
    flag=1
    break
if(flag==0):
	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()))

sum_A = 0
A_list = []
for i in range(len(A)):
    sum_A += A[i]
    A_list.append(sum_A)
    if sum_A>K:
        break
A = A[:i]

sum_B = 0
B_list = []
for i in range(len(B)):
    sum_B += B[i]
    B_list.append(sum_B)
    if sum_B>K:
        break
B = B[:i]

num = []
cost = []
if (len(A)==0)&(len(B)==0):
    ans = 0
elif (len(A)==0)&(len(B)!=0):
    ans = len(B)
elif (len(A)!=0)&(len(B)==0):
    ans = len(A)
else:
    num.append(len(A))
    cost.append(sum(A))
    num.append(len(B))
    cost.append(sum(B))
    
    for i in range(len(A)):
        for j in range(len(B)):
            if A_list[i]+B_list[j]>K:
                break
            else:
                num.append(i+j+2)
                cost.append(A_list[i]+B_list[j])
    num = np.array(num)
    cost = np.array(cost)
    num = num[cost<=K]
    cost = cost[cost<=K]
    ans = max(num)

print(ans)

Submission status: Wrong Answer

Solution code:
a,b,money=list(map(int,input().split()))
A=[0]+list(map(int,input().split()))
B=[0]+list(map(int,input().split()))
for i in range(1,a+1):
  A[i]+=A[i-1]
for j in range(1,b+1):
  B[j]+=B[j-1]
b_cnt=b
for a_cnt in range(a+1):
  if A[a_cnt]>money:
    continue
  while A[a_cnt]+B[b_cnt]>money:
    b_cnt-=1
  ans=max(0,a_cnt+b_cnt)
print(ans)

Submission status: Wrong Answer

Solution code:
#C - Tsundoku
from collections import deque
N,M,K = map(int,input().split())
A = deque(map(int,input().split()))
B = deque(map(int,input().split()))

A.append(float('inf'))
B.append(float('inf'))

time = K 
count = 0
sum_A = sum(list(A)[:-1])
sum_B = sum(list(A)[:-1])
for _ in range(len(A)+len(B)):
    if A[0] > B[0]:
        target = B.popleft()
        if (target > (sum_A-A[0])) and len(A) != 1:
            sum_A -= A[0]
            B.appendleft(target) 
            target = A.popleft()
        time -= target
        count += 1
        print('B',count,target,time)
    else:
        target = A.popleft()
        if (target > (sum_B-B[0])) and len(B) != 1:
            sum_B -= B[0]
            A.appendleft(target)
            target = B.popleft()
        time -= target
        count += 1
        print('A',count,target,time)
    if len(A) == len(B) == 1:
        break
    if time < 0:
        count -= 1
        break 
    elif time == 0:
        break
print(count)

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

A.append(float('inf'))
B.append(float('inf'))

time = K 
count = 0
sum_A = sum(list(A)[:-1])
sum_B = sum(list(A)[:-1])
for _ in range(len(A)+len(B)):
    if A[0] > B[0]:
        target = B.popleft()
        if (target > (sum_A-A[0])) and len(A) != 1:
            sum_A -= A[0]
            B.appendleft(target) 
            target = A.popleft()
        time -= target
        count += 1
    else:
        target = A.popleft()
        if (target > (sum_B-B[0])) and len(B) != 1:
            sum_B -= B[0]
            A.appendleft(target)
            target = B.popleft()
        time -= target
        count += 1
    if len(A) == len(B) == 1:
        break
    if time < 0:
        count -= 1
        break 
    elif time == 0:
        break
print(count)

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

A.append(float('inf'))
B.append(float('inf'))

time = K 
count = 0
for _ in range(len(A)+len(B)):
    if A[0] > B[0]:
        target = B.popleft()
        if (target > sum(list(A)[1:-1])) and len(A) != 1:
            B.appendleft(target) 
            target = A.popleft()
        time -= target
        count += 1
    else:
        target = A.popleft()
        if (target > sum(list(B)[1:-1])) and len(B) != 1:
            A.appendleft(target)
            target = B.popleft()
        time -= target
        count += 1
    if len(A) == len(B) == 1:
        break
    if time < 0:
        count -= 1
        break 
    elif time == 0:
        break
print(count)

Submission status: Wrong Answer

Solution code:
#C - Tsundoku
from collections import deque
N,M,K = map(int,input().split())
A = deque(map(int,input().split()))
B = deque(map(int,input().split()))

A.append(float('inf'))
B.append(float('inf'))

time = K 
count = 0
for _ in range(len(A)+len(B)):
    
    if A[0] > B[0]:
        target = B.popleft()
        if sum(B) < A[0]:
            B.appendleft(target) 
            target = A.popleft()
        time -= target
        count += 1
    else:
        target = A.popleft()
        if sum(A) < B[0]:
            A.appendleft(target)
            target = B.popleft
        time -= target
        count += 1
    if len(A) ==1 and len(B) == 1:
        break
    if time < 0:
        count -= 1
        break
    elif time == 0:
        break
print(count)

Submission status: Wrong Answer

Solution code:
#C - Tsundoku
from collections import deque
N,M,K = map(int,input().split())
A = deque(map(int,input().split()))
B = deque(map(int,input().split()))

A.append(float('inf'))
B.append(float('inf'))

time = K 
count = 0
for _ in range(len(A)+len(B)):
    
    if A[0] > B[0]:
        time -= B[0]
        B.popleft()
        count += 1
    else:
        time -= A[0]
        A.popleft()
        count += 1
    if len(A) == len(B) == 1:
        break
    if time < 0:
        count -= 1
        break
    elif time == 0:
        break
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()))

sumA = [0]
sumB = [0]
for i in range(N):
    sumA.append(A[i] + sumA[i])
for i in range(M):
    sumB.append(B[i] + sumB[i])

ans = 0
for i in range(len(sumA)):
    time = K - sumA[i]
    if time < 0:
        book = i - 1
        if ans <= book:
            ans = book
        break
    for j in range(len(sumB)):
        t = time - sumB[j]
        if t < 0:
            book = i + j - 1
            if ans <= book:
                ans = book
            break
        if j == len(B) and 0 <= t:
            ans = N + M

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

line = [int(i) for i in input().rstrip().split()]
N = line[0]
M = line[1]
K = line[2]

A = [int(i) for i in input().rstrip().split()]
B = [int(i) for i in input().rstrip().split()]

A1 = [sum(A[0:i+1]) for i in range(len(A))]
B1 = [sum(B[0:i+1]) for i in range(len(B))]
num_book = np.array([])

for i in range(len(A1)):
  for j in range(len(B1)):
    if A1[i]+B1[j] <= K:
      num_book = np.append(num_book, i+j+2)
      
if len(num_book) != 0:
  print(int(np.max(num_book))) 
else:
  print(0)

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_cumsum, B_cumsum = [0], [0]

for i in range(n):
    A_cumsum.append(A_cumsum[i] + A[i])
    
for j in range(m):
    B_cumsum.append(B_cumsum[j] + B[j])
    
ans = 0

for i, a in enumerate(A_cumsum):
    if a > k:
        break
    
    for j, b in enumerate(B_cumsum):
        if a + b > k:
            break
        elif (i + j) < ans:
            break
        else:
            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 = 0
ans = 0
a_next = a.pop(0)
b_next = b.pop(0)

while True:
        
    if a_next <= b_next:
        time += a_next
        try:
            a_next = a.pop(0)
        except:
            a_next = 200001
    
    else:
        time += b_next
        try:
            b_next = b.pop(0)
        except:
            b_next = 200001
    
    if time <= k:
        ans += 1
    else:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
OFFSET = 97
def main():
    n,m,k = map(int,input().split())
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))

    total = 0
    a_index = 0
    b_index = 0
    while a_index != len(A):
        if total + A[a_index] <= k:
            total += A[a_index]
            a_index += 1
        else:
            break
    
    a_index -= 1
    
    while b_index != len(B):
        if total + B[b_index] <= k:
            total += B[b_index]
            b_index += 1
        else:
            break

    b_index -= 1
    
    ans = a_index + b_index + 2
    while a_index != -1:
        total -= A[a_index]
        a_index -= 1
        while b_index != len(B):
            if total + B[b_index] <= k:
                total += B[b_index]
                b_index += 1
            else:
                break
        b_index -= 1

        if ans < a_index + b_index + 2 :
            ans = a_index + b_index + 2

    print(ans)



    


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

print(a)
print(b)
cnt = 0
while k >= 0:
    cnt += 1
    if a[0] <= b[0]:
        k -= a[0]
        del a[0]
        a.append(10**9)
    else:
        k -= b[0]
        del b[0]
        b.append(10**9)
print(cnt-1)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))
out = lambda x: print('\n'.join(map(str, x)))

n, m, k = inm()
a = inl()
b = inl()
count = 0
for i in range(n-1):
    a[i+1] += a[i]
for i in range(m-1):
    b[i+1] += b[i]
for i in range(n):
    j = m-1
    if a[i] > k:
        break
    while a[i] + b[j] > k and j >= 0:
        j -= 1
    count = max(count, i+j + 2)
print(count)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))
out = lambda x: print('\n'.join(map(str, x)))

n, m, k = inm()
a = inl()
b = inl()
c = [0] * (n+m)
i = j = 0
for x in range(n+m):
    if i == n:
        c[x] = b[j]
        j += 1
        continue
    if j == m:
        c[x] = a[i]
        i += 1
        continue       
    if a[i] >= b[j]:
        c[x] = b[j]
        j += 1
    else:
        c[x] = a[i]
        i += 1   
count = 0
for i in range(n+m):
    if c[i] < k:
        k -= c[i]
        count += 1
    elif c[i] == k:
        count += 1
    else:
        break
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,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 = 0
j = 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()))

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 = 0
j = 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(map(int,input().split()))
B = list(map(int,input().split()))
a = [0]
b = [0]
for i in range(n):
  a.append(a[i]+A[i])
for i in range(m):
  b.append(b[i]+B[i])
ans = -100
for i in range(n):
  if(a[i]>k):
    break
  for j in range(1,m):
    if(a[i]+b[(-1)*j]>k):
      break
    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()))
for i in range(1,n):
  a[i] += a[i-1]
for  i in range(1,m):
  b[i] += b[i-1]
ans = -100
for i in range(n):
  if(a[i]>k):
    break
  for j in range(1,m):
    if(a[i]+b[(-1)*j]>k):
      break
    ans = max(ans,i+j+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()))
for i in range(1,n):
  a[i] += a[i-1]
for  i in range(1,m):
  b[i] += b[i-1]
ans = -100
for i in range(n):
  if(a[i]>k):
    break
  for j in range(1,m):
    if(a[i]+b[(-1)*j]>k):
      break
    ans = max(ans,i+j+2)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
import bisect

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

a_acc = [0] + list(accumulate(a))  # aを0冊読む=1冊も読まない場合があるので、[0]を先頭に追加します
b_acc = list(accumulate(b))  # bisect_rightでは、x以下の要素がいくつあるか？を求めるので、こちらに0は入れません

ans = 0
for an in range(n + 1):
    rem = k - a_acc[an]
    if rem < 0:
        # aをこれ以上読めません
        break

    bn = bisect.bisect_right(b_acc, rem)
    ans = max(ans, an + bn)

print(ans)
print(b_acc)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
arr1=list(map(int,input().split()))
arr2=list(map(int,input().split()))
acum1=[0]
for i in range(n): #累積和ai,bjを求める
    acum1.append(acum1[-1]+arr1[i])
    acum2=[0]
for i in range(m):
    acum2.append(acum2[-1]+arr2[i])
    ans=0
    j=m
for i in range(n+1):
    if acum1[i]>k: #ai>Kであれば、どのようにjを選んでもai+bj<=Kとなることはないので探索を終了する
        break
    while acum2[j]>k-acum1[i] and j>0: #各iについて、bj<=K-aiを満たす最大のjを求める
        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()))

i=0
j=0
time=0

while(True):
    if i>=n and j>=m:
        break
    elif i>=n:
        time += b[j]
        j += 1
    elif j >= m:
        time += a[i]
        i += 1
    else:
        if a[i]<b[j]:
            time +=a[i]
            i += 1
        else:
            time += b[j]
            j += 1
    if time >k:
        i -= 1
        break

print(i+j)

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()))
sum_time = 0
now_read_book = 0
ans = 0
now_A = 0

for i in range(N):
  if sum_time + A[i] <= K:
    sum_time += A[i]
    now_read_book += 1
    now_A = i
  else:
    break
ans = now_read_book

for i in range(M):
  if sum_time + B[i] > K:
    while sum_time + B[i] > K and now_A >= 0:
      sum_time -= A[now_A]
      now_A -= 1
      now_read_book -= 1
  if sum_time + B[i] <= K:
    sum_time += B[i]
    now_read_book += 1
  if now_read_book > ans:
    ans = now_read_book
print(ans)