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 math

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

A.append(math.inf)
B.append(math.inf)
A.reverse()
B.reverse()

score = 0
while K >= min(A[-1], B[-1]):
    if A[-1] < B[-1]:
        K -= A.pop()
    else:
        K -= B.pop()
    score += 1

print(score)

Submission status: Wrong Answer

Solution code:
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()]

number=0
time=0
x=0
y=0

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

Submission status: Wrong Answer

Solution code:
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()]

number=0
time=0
x=0
y=0

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

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()))
ssum = ssum_max = 0
is_exceed = False
for i in range(N):
    ssum += A[i]
    new_ssum = ssum
    for j in range(M):
        new_ssum += B[j]
        # print(i, j, new_ssum, ssum_max)
        if new_ssum > K:
            is_exceed = True
            if j > 0:
                ssum_max = max(ssum_max, i + j + 1)
            break
if ssum_max == 0:
    if is_exceed:
        ssum_max = 0
    else:
        ssum_max = N + M
print(ssum_max)

Submission status: Wrong Answer

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

s_a=[0]
s_b=[0]

for i in a_ls:
	s_a+=[s_a[-1]+i]


for i in b_ls:
	s_b+=[s_b[-1]+i]

ans=0
numA=0

for i in range(M+1):
	time_b=s_b[M-i]
	while time_b+s_a[min(N,numA+1)]<=K and numA<=(N-1):
		numA+=1
		ans=max(ans,numA+(M-i))


print(ans)

# 2darray [[0] * 4 for i in range(3)]
# import itertools

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(' ')))
sa = [0] * (n+1)
sb = [0] * (m+1)

for i in range(n):
  sa[i+1] = a_list[i] + sa[i]
for j in range(m):
  sb[j+1] = b_list[j] + sb[j]

best=0
r = m
for a in a_list:
  if a>k:
    break
  while ((a + sb[r]) > k) & (r>=0):
    r-=1
    
  best = max(best,i+j+2)
      
  
    
print(best)

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(' ')))
a_sum = 0
b_sum = sum(b_list)

j = m-1
best=0
for i, a in enumerate(a_list):
  a_sum+=a
  if a_sum>k:
    break
  while ((a_sum + b_sum) > k) & (j>=0):
    b_sum-=b_list[j]
    j-=1
    
  best = max(best,i+j+2)
      
  
    
print(best)

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(' ')))
a_sum = 0
b_sum = sum(b_list)

j = len(b_list)-1
best=0
for i, a in enumerate(a_list):
  a_sum+=a
  while ((a_sum + b_sum) > k) & (j>=0):
    b_sum-=b_list[j]
    j-=1
  if (a_sum + b_sum) <= k:
    if i+j+2 > best:
      best=i+j+2
  
    
print(best)

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(' ')))
a_sum = 0
b_sum = sum(b_list)

j = len(b_list)-1
best=0
for i, a in enumerate(a_list):
  a_sum+=a
  while ((a_sum + b_sum) > k) & (j>=0):
    b_sum-=b_list[j]
    j-=1
  if (i+j+2) > best:
    best=i+j+2
  
    
print(best)

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(' ')))
a_sum = 0
b_sum = sum(b_list)

j = len(b_list)-1
best=0
for i, a in enumerate(a_list):
  a_sum+=a
  while ((a_sum + b_sum) > k) & (j>=0):
    b_sum-=b_list[j]
    j-=1
  if j==-1:
    break
  if (i+j+2) > best:
    best=i+j+2
  
    
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(10000000000)
b.append(10000000000)
count = -1
s = 0
for _ in range(n + m +1):
    if a[0] < b[0]:
      count += 1
      s += a[0]
      a.remove(a[0])
    elif a[0] == b[0]:
      if sum(a[0:1]) < sum(b[0:1]):
        count += 1
        s += a[0]
        a.remove(a[0])
      else:
        count += 1
        s += b[0]
        b.remove(b[0])        
    else:
      count += 1
      s += b[0]
      b.remove(b[0])
    if s > k:
      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()))

ans = 0
time = 0

for i in range(n+m):
  plus = 0
  if len(A) == 0:
    plus = B.pop(0)
  elif len(B) == 0:
    plus = A.pop(0)
  elif A[0] < B[0]:
    plus = A.pop(0)
  else:
    plus = B.pop(0)
  
  time += plus
  #print(time)
  if time > k:
    break
  
  ans += 1

print(ans)

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

dp = [[-1] * (m + 1) for i in range(n + 1)]

dp[0][0] = 0

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

for i in range(m):
    dp[0][i + 1] = dp[0][i] + b[i]

ans = 0

for i in range(1, n + 1):
    for j in range(1, m + 1):
        dp[i][j] = dp[i][0] + dp[0][j]
        if dp[i][j] > k:
            break
        else:
            ans = max(ans, i + j)


print("{}".format(ans))

Submission status: Wrong Answer

Solution code:
from collections import deque
from itertools import chain
B = [0]
N, M, K = list(map(int, input().split()))
A = deque(map(int, input().split()))
A.appendleft(0)
B.extend(list(map(int, input().split())))

a = 0
for i in range(N+1):
    a += A[i]
    if a < K:
        max_a = i
        
b = 0
for j in range(M+1):
    b += B[j]
    #print(j, b, K)
    if b < K:
        max_b = j
        
result = [[0] * (max_a+1) for _ in range(max_b+1)]
a = 0
rest = 10^9

for i in range(max_a+1):
    a += A.popleft()
    rest = K - a
    _rest = rest
    for j in range(max_b+1):
        _rest -= B[j]
        if _rest >= 0:
            result[j][i] = i + j
print(max(list(chain(*result))))

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=a+b
c.reverse()
ans=0
t=0
if sum(c)<=k:
    print(n+m)
else:
    for i in range(n+m-1,-1,-1):
        if c[i]>=c[i-n]:
            t+=c[i-n]
            if t<=k:
                ans+=1
                c.remove(c[i-1])
            else:
                break
        else:
            t+=c[i]
            if t<=k:
                ans+=1
                c.remove(c[i])
            else:
                break
    print(ans)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ct = 0
for i in range(N + M):
    if i >= N:
        if i >= M:
            print(N+M)
            exit()
        else:
            K = K - B[i]
            if K < 0:
                break
            else:
                ct += 1
    elif i >= M:
        K = K - A[i]
        if K < 0:
            break
        else:
            ct += 1
    elif A[i] <= B[i]:
        K = K - A[i]
        if K < 0:
            break
        else:
            ct += 1
    else:
        K = K - B[i]
        if K < 0:
            break
        else:
            ct += 1
print(ct)

Submission status: Wrong Answer

Solution code:
n,m,k = map(int,input().split())
lsa = list(map(int,input().split()))
lsb = list(map(int,input().split()))
import numpy 
la = [0]+[e for e in numpy.cumsum(numpy.array(lsa)) if e <= k]
lb = [0]+[e for e in numpy.cumsum(numpy.array(lsb)) if e <= k]
print(la)
print(lb)
mx = 0
for i in range(len(la)):
    for j in range(len(lb)):
        a = la[i]+lb[j]
        if a <= k:
            if i+j > mx:
                mx = i+j
print(mx)

Submission status: Wrong Answer

Solution code:
n,m,k = map(int,input().split())
lsa = list(map(int,input().split()))
lsb = list(map(int,input().split()))
import numpy 
la = [e for e in numpy.cumsum(numpy.array(lsa)) if e <= k]
lb = [e for e in numpy.cumsum(numpy.array(lsb)) if e <= k]
mx = 0
for i in range(len(la)):
    for j in range(len(lb)):
        a = la[i]+lb[j]
        if a <= k:
            if i+j+2 > mx:
                mx = i+j+2
print(mx)

Submission status: Wrong Answer

Solution code:
n,m,k = map(int,input().split())
lsa = list(map(int,input().split()))
lsb = list(map(int,input().split()))
import numpy 
na = [e for e in numpy.cumsum(numpy.array(lsa)) if e <= k]
nb = [e for e in numpy.cumsum(numpy.array(lsb)) if e <= k]
mx = 0
for i in range(len(na)):
    for j in range(len(nb)):
        a = na[i]+nb[j]
        if a <= k:
            if i+j+2 > mx:
                mx = i+j+2
print(mx)

Submission status: Wrong Answer

Solution code:
n,m,k = map(int,input().split())
lsa = list(map(int,input().split()))
lsb = list(map(int,input().split()))
import numpy 
na = numpy.cumsum(numpy.array(lsa)) 
nb = numpy.cumsum(numpy.array(lsb)) 
mx = 0
for i in range(len(na)):
    for j in range(len(nb)):
        a = na[i]+nb[j]
        if a <= k:
            if i+j+2 > mx:
                mx = i+j+2
print(mx)

Submission status: Wrong Answer

Solution code:
import numpy as np
n,m,k=map(int,input().split())
A=[0]+list(map(int, input().split()))
B=[0]+list(map(int, input().split()))
ans=0
a=np.cumsum(np.array(A)).tolist()
b=np.cumsum(np.array(B)).tolist()
for i in range(n+1):
    if k<a[i]:
        break
    j=m
    while b[j]>k-a[i]:
        j-=1
        ans=max(ans,i+j)
print(ans)

Submission status: Wrong Answer

Solution code:
#! python3
# coding:utf-8
 
def main():
    n,m,k = map(int,input().split())
    alist = list(map(int,input().split()))
    blist = list(map(int,input().split()))
    
    aindex=0
    bindex=0
    time=0
    
    if (alist[0]>k)and(blist[0]>k):
        print("0")
        exit()

    for i in range(n+m):

        if (aindex < len(alist)) and (bindex < len(blist)):
            if alist[aindex]<=blist[bindex]:
                time += alist[aindex]
                aindex+=1
            else:
                time += blist[bindex]
                bindex+=1

        elif (aindex >= len(alist)) and (bindex < len(blist)):
            time += blist[bindex]
            bindex+=1
        
        elif (bindex >= len(blist)) and (aindex < len(alist)):
            time += alist[aindex]
            aindex+=1
        
        elif (bindex >= len(blist)) and (aindex >= len(alist)):
            print(i+1)
            break
        
        if time>=k:
            print(i+1)
            break


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
INF = 10**10
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a_cnt, b_cnt = 0, 0
a = A[a_cnt]
b = B[b_cnt]
while True:
  if a == INF and b == INF:
    break
  elif a <= b:
    K -= a
    if K >= 0:
      a_cnt += 1
      if len(A) > a_cnt:
        a = A[a_cnt]
      else:
        a = INF
    else:
      break
  else:
    K -= b
    if K >= 0:
      b_cnt += 1
      if len(B) > b_cnt:
        b = B[b_cnt]
      else:
        b = INF
    else:
      break
print(a_cnt+b_cnt)

Submission status: Wrong Answer

Solution code:
INF = 10**10
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a_cnt, b_cnt = 0, 0
a = A[a_cnt]
b = B[b_cnt]
while True:
  if a == INF and b == INF:
    break
  elif a <= b:
    K -= a
    if K >= 0:
      a_cnt += 1
      if len(A) > a_cnt:
        a = A[a_cnt]
      else:
        a = INF
    else:
      break
  elif b < a:
    K -= b
    if K >= 0:
      b_cnt += 1
      if len(B) > b_cnt:
        b = B[b_cnt]
      else:
        b = INF
    else:
      break
print(a_cnt+b_cnt)

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 _ in range(n):
    acum1.append(acum1[-1] + arr1[_])

acum2 = [0]
for _ in range(m):
    acum2.append(acum2[-1] + arr2[_])

ans = 0
j = m
for i in range(n):
    if acum1[i]>k:
        break
    while acum2[j]>k-acum1[i] and j>0:
        j -= 1
    ans = max(ans,i+j)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque

N, M, K = list(map(int, input().split()))
A = deque(map(int, input().split()))
B = deque(map(int, input().split()))
count = 0
while (N != 0 or M != 0):
    if N <= 0 and M > 0 and B[0] <= K:
        K -= B[0]
        count += 1
        B.popleft()
        M -= 1
    elif M <= 0 and N > 0 and A[0] <= K:
        K -= A[0]
        count += 1
        A.popleft()
        N -= 1
    elif M > 0 and N > 0 and A[0] <= B[0] and A[0] <= K:
        K -= A[0]
        count += 1
        A.popleft()
        N -= 1
    elif M > 0 and N > 0 and B[0] < A[0] and B[0] <= K:
        K -= B[0]
        count += 1
        B.popleft()
        M -= 1
    else:
        break
print(count)

Submission status: Wrong Answer

Solution code:
import sys
import bisect

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

a_cs = [0]
for i in range(n):
    a_cs.append(a_cs[i] + a[i])
b_cs = [0]
for i in range(m):
    b_cs.append(b_cs[i] + b[i])
b_cs.append(10**20)
# print(type(a_cs[1]))
ans = 0

if min(a + b) > k:
    print(0)
    sys.exit()

for i in range(len(a_cs)):
    ans = max(ans, i + 1 + bisect.bisect_right(b_cs, (k - a_cs[i])))

print(ans)

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):
    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:
        break
    while acum2[j] < k - acum1[i] and j > 0:
        ans  = max(ans, i+j)
        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()))
a=0
b=sum(B)
ans=0
for i in range(N):
    a+=A[i]
    if a>K:
        break
    while a+b>K:
        b-=B[-1]
        B.pop(-1)
        M-=1
    ans=max(ans,i+M+1)
print(ans)

Submission status: Wrong Answer

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

a, b = [0], [0]

for i in range(N):
    a.append(a[i] + A[i])

for i in range(M):
    b.append(B[i] + B[i])

ans, j = 0, M

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

Submission status: Wrong Answer

Solution code:
import sys

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

ab = sorted(a + b)
# print(ab)
# print(len(ab))

if ab[0] > k:
    print(0)
    sys.exit()

if sum(ab) <= k:
    print(len(ab))
    sys.exit()

for i in range(len(ab)):
    k -= ab[i]
    if k < ab[i + 1]:
        print(i + 1)
        sys.exit()

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

num = 0
ans = 0
i = 0
j = 0
while i < n or j < m:
    if i >= n:
        ans += b[j]
        j += 1
    elif j >= m:
        ans += a[i]
        i += 1
    else:
        if a[i] > b[j]:
            ans += b[j]
            j += 1
        elif a[i] < b[j]:
            ans += a[i]
            i += 1
        else:
            if i + 1 >= n:
                ans += b[j]
                j += 1
            elif j + 1 >= m:
                ans += a[i]
                i += 1
            else:
                if a[i+1] < b[j+1]:
                    ans += a[i]
                    i += 1
                else:
                    ans += b[j]
                    j += 1
    if k < ans:
        break
    else:
        num += 1
print(num)

Submission status: Wrong Answer

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

t=0
count=0
i=0
j=0

if(K>=A[0] or K>=B[0]):
  for i in range(N+K):
    if(K<t):
      count = i
      break
    
    elif(len(A)==0 and len(B)==0):
      count = i
      break
    
    elif(len(A)==0):
      t += B.pop(0)
  
    elif(len(B)==0):
      t += A.pop(0)
  
    else:
      if(A[0]>B[0]):
        t += A.pop(0)
      else:
        t += B.pop(0)
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()))

t=0
count=0
i=0
j=0

if(K>A[0] and K>B[0]):
  while(K>t):
    if(len(A)==0):
      t += B.pop(0)
      count += 1
  
    elif(len(B)==0):
      t += A.pop(0)
      count += 1
  
    else:
      if(A[0]>B[0]):
        t += A.pop(0)
        count += 1
      else:
        t += B.pop(0)
        count += 1

print(count)

Submission status: Wrong Answer

Solution code:
#template
def inputlist(): return [int(j) for j in input().split()]
#template
N,M,K = inputlist()
A = inputlist()
B = inputlist()
if sum(A) + sum(B) <= K:
    print(N+M)
    exit()
time = 0
count = 0
i = 0
j = 0
flag1 = 1
flag2 = 1
while time < K:
    tmp = 0
    if flag1 and flag2:
        tmp = min(A[i],B[j])
    if flag1 == 0 and flag2 == 1:
        tmp = B[j]
    if flag1 == 1 and flag2 == 0:
        tmp = A[i]
    if A[i] == tmp:
        i +=1
        if i == N:
            flag1=0
            i = N-1
    if B[j] == tmp:
        j +=1
        if j == M:
            flag2 = 0
            j = M-1
    time += tmp
    count +=1
print(count-1)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

k=0; ia=0; ib=0
while k<=K:
    if ia==N and ib==M:
        break
    elif ia<N and ib<M:
        if A[ia]<=B[ib]:
            k+=A[ia]; ia+=1
        else:
            k+=B[ib]; ib+=1
    elif ia < N:
        k+=A[ia]; ia+=1
    else:
        k+=B[ib]; ib+=1
        
if k>K:
    print(ia+ib-1)
else:
    print(ia+ib)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right
from numpy import cumsum
from sys import stdin
input=stdin.readline
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
a=cumsum(a)
b=cumsum(b)
z=b[0]
ans=0
for i in range(len(a)):
  x=k-a[i]
  if x>=z:
    y=bisect_right(b,x)
    if ans<y+i+1:
      ans=y+i+1
  elif x>=0:
    if ans<i+1:
      ans=i+1
print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right
from numpy import cumsum
from sys import stdin
input=stdin.readline
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
a=cumsum(a)
b=cumsum(b)
z=b[0]
ans=0
for i in range(len(a)):
  x=k-a[i]
  if x>=0:
    y=bisect_right(b,x)
    if ans<y+i+1:
      ans=y+i+1
print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right
from numpy import cumsum
from sys import stdin
input=stdin.readline
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
a=cumsum(a)
b=cumsum(b)
ans=0
for i in range(len(a)):
  x=k-a[i]
  if x>=0:
    y=bisect_right(b,x)
    if ans<y+i+1:
      ans=y+i+1
print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right
from numpy import cumsum
from sys import stdin
input=stdin.readline
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
a=cumsum(a)
b=cumsum(b)
ans=0
if a[0]<k:
  for i in range(len(a)):
    x=k-a[i]
    y=bisect_right(b,x)
    print(y)
    if ans<y+i+1:
      ans=y+i+1
print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right
from numpy import cumsum
from sys import stdin
input=stdin.readline
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
a=cumsum(a)
b=cumsum(b)
ans=0
for i in range(len(a)):
  x=k-a[i]
  y=bisect_right(b,x)
  if ans<y+i+1:
    ans=y+i+1
print(ans)

Submission status: Wrong Answer

Solution code:
n,m,sus = map(int,input().split()); ans,l,r,ct = 0,0,0,0
A,B = list(map(int,input().split())),list(map(int,input().split()))
while ans < sus:
  if min(A[l],B[r]) == A[l]:
    if ans + A[l] > sus : break
    ans += A[l]; A[l] = 2e10; l = (l+1)%n; ct +=1
  else: 
    if ans + B[r] > sus : break
    ans += B[r]; B[r] = 2e10; r = (r+1)%m; ct += 1
print(ct)

Submission status: Wrong Answer

Solution code:
n,m,sus = map(int,input().split()); ans,l,r,ct = 0,0,0,0
A,B = list(map(int,input().split())),list(map(int,input().split()))
for x in range(n+m):
  if min(A[l],B[r]) == A[l]:
    if ans + A[l] > sus: break
    ans += A[l]; A[l] = 2e10; l = (l+1)%n; ct +=1
  else: 
    if ans + B[r] > sus: break
    ans += B[r]; B[r] = 2e10; r = (r+1)%m; ct += 1
print(ct)

Submission status: Wrong Answer

Solution code:
import math
def facts(n):
    ans = []
    for  i in range(1, int(math.sqrt(n)+1)):
        if(n%i==0):
            ans.append(i)
            ans.append(n//i)
    ans = sorted(list(dict.fromkeys(ans)))
    if(ans[-1]==n):
        ans = ans[:-1]
    return ans


n, m,k  = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
pa  = [a[0]]
pb = [b[0]]
ans = 0
for i in range(1, n):
    pa.append(a[i]+pa[i-1])
for i in range(1, m):
    pb.append(b[i]+pb[i-1])
for c in range(n):
    tmp=pa[c]
    if(tmp > k):
        break
    else:
        for d in range(m):
            if(pb[d]<= k-tmp):
                ans = max(ans, c+d+2)
            else:
                break
print(ans)

Submission status: Wrong Answer

Solution code:
import math
def facts(n):
    ans = []
    for  i in range(1, int(math.sqrt(n)+1)):
        if(n%i==0):
            ans.append(i)
            ans.append(n//i)
    ans = sorted(list(dict.fromkeys(ans)))
    if(ans[-1]==n):
        ans = ans[:-1]
    return ans


n, m,k  = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
pa  = [a[0]]
pb = [b[0]]
ans = 0
for i in range(1, n):
    pa.append(a[i]+pa[i-1])
for i in range(1, m):
    pb.append(b[i]+pb[i-1])
for c in range(n):
    tmp=pa[c]
    for d in range(m):
        if(pb[d]+ tmp<= k):
            ans = max(ans, c+d+2)
        else:
            break
print(ans)

Submission status: Wrong Answer

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

dp_A = [0]*N
dp_B = [0]*M
dp_A[0] = A[0]
dp_B[0] = B[0]

for a in range(1, N):
    dp_A[a] += dp_A[a-1] + A[a]

for b in range(1, M):
    dp_B[b] += dp_B[b-1] + B[b]
ans = 0

for i in range(N):
    for j in range(M):
        if dp_A[i] + dp_B[j] <= K:
            ans = max(ans, i+j+2)
        elif K - dp_A[i] < dp_B[j]:
            break
        else:
            break
print(ans)

Submission status: Wrong Answer

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

dp_A = [0]*N
dp_B = [0]*M
dp_A[0] = A[0]
dp_B[0] = B[0]

for a in range(1, N):
    dp_A[a] += dp_A[a-1] + A[a]

for b in range(1, M):
    dp_B[b] += dp_B[b-1] + B[b]
ans = 0
for i in range(N):
    for j in range(M):
        if dp_A[i] + dp_B[j] <= K:
            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()))
 
cnt, i, j, time = 0, 0, 0, 0
 
while i < n and j < m:
    if time + min(a[i], b[j]) > k:
        break
    time += min(a[i], b[j])
    if a[i] <= b[j]:
        i += 1
    else:
        j += 1
    cnt += 1
 
while i < n:
    if time + a[i] > k:
        break
    time += a[i]
    cnt += 1
    i += 1
  
while j < m:
    if time + b[j] > k:
        break
    time += b[j]
    cnt += 1
    j += 1
print(cnt)

Submission status: Wrong Answer

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

def book_pop():
    if A and B:
        return A.pop() if A[-1] <= B[-1] else B.pop()
    
    elif not A and not B:
        return 0
    
    else:
        return A.pop() if A else B.pop()


for x in range(N+M+1):
    K -= book_pop()
    if K <= 0:
        break
    
print(x)

Submission status: Wrong Answer

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

def book_pop():
    if A and B:
        return A.pop() if A[-1] <= B[-1] else B.pop()
    
    elif not A and not B:
        return 0
    
    else:
        return A.pop() if A else B.pop()


for x in range(N+M+1):
    K -= book_pop()
    if K < 0:
        break
    
print(x)

Submission status: Wrong Answer

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

def book_pop():
    if A and B:
        return A.pop() if A[-1] <= B[-1] else B.pop()
    
    elif not A and not B:
        return 0
    
    else:
        return A.pop() if A else B.pop()


for x in range(N+M+1):
    print(K, x)
    K -= book_pop()
    if K < 0:
        break
    
print(x)

Submission status: Wrong Answer

Solution code:
'''ABC172 C'''
import numpy as np
n,m,k = map(int,input().split())
a = np.array([int(i) for i in input().split()], dtype='int64')
b = np.array([int(i) for i in input().split()], dtype='int64')

a_c = np.zeros(n+1,dtype='int64')
a_c[1:] = np.cumsum(a)

b_c = np.zeros(m+1,dtype='int64')
b_c[1:] = np.cumsum(b)

a_c = a_c[a_c <= k]
b_c = b_c[b_c <= k]
ans = 0
for i,ai in enumerate(a_c):
    n = np.searchsorted(b_c, k - ai, side = 'right')
    ans = max(i + n, ans)
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
n,m,k = map(int,input().split())
a = np.array([int(i) for i in input().split()], dtype='int64')
b = np.array([int(i) for i in input().split()], dtype='int64')

a_c = np.cumsum(a)
b_c = np.cumsum(b)

a_c = a_c[a_c <= k]
b_c = b_c[b_c <= k]
ans = 0
if len(a_c) == 0 and len(b_c) == 0:
    ans = 0
elif len(a_c) == 0 and len(b_c) != 0:
    ans = np.searchsorted(b_c, k, side = 'right')
elif len(a_c) != 0 and len(b_c) == 0:
    ans = np.searchsorted(a_c, k, side = 'right')
else:
    for i,ai in enumerate(a_c):
        n = np.searchsorted(b_c, k - ai, side = 'right')
        ans = max(i+1 + n, ans)
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
n,m,k = map(int,input().split())
a = np.array([int(i) for i in input().split()], dtype='int64')
b = np.array([int(i) for i in input().split()], dtype='int64')

a_c = np.cumsum(a)
b_c = np.cumsum(b)

a_c = a_c[a_c <= k]
b_c = b_c[b_c <= k]
ans = 0
if len(a_c) == 0:
    ans = np.searchsorted(b_c, k, side = 'right')
else:
    for i,ai in enumerate(a_c):
        n = np.searchsorted(b_c, k - ai, side = 'right')
        ans = max(i+1 + n, ans)
    
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
n,m,k = map(int,input().split())
a = np.array([int(i) for i in input().split()], dtype='int64')
b = np.array([int(i) for i in input().split()], dtype='int64')

a_c = np.cumsum(a)
b_c = np.cumsum(b)

a_c = a_c[a_c <= k]
b_c = b_c[b_c <= k]
ans = 0
for i,ai in enumerate(a_c):
    n = np.searchsorted(b_c, k - ai, side = 'right')
    ans = max(i+1 + n, ans)
    
print(ans)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
A = []
B = []
a, *an = map(int, input().split())
A.append(a)
A += an
b, *bn = map(int, input().split())
B.append(b)
B += bn
#print(A)
#print(B)
cost = 0
i = 0
A_cos = []
B_cos = []

while cost <= K and i < len(A):
    cost += A[i]
    A_cos.append(cost)
    i +=1
    
i = 0
cost = 0
while  cost <= K and i < len(B):
    cost += B[i]
    B_cos.append(cost)
    i +=1
    
#print(A_cos)
#print(B_cos)

an = 0
bn = 0
num = 0

while an < len(A_cos):
    a_cost = A_cos[an]
    while bn < len(B_cos):
        b_cost = B_cos[bn]
        #print(an+1, bn+1, a_cost, b_cost)
        if a_cost + b_cost <= K and an+1 + bn+1 > num:
            #print("kousin:", str(num))
            num = an + 1 + bn + 1
        bn += 1
    bn = 0
    an += 1
    
print(num)