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:
from collections import deque

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

A = deque([int(x) for x in input().split()])
B = deque([int(y) for y in input().split()])

account = 0
cnt = 0
while account <= K:
    cnt += 1
    
    if len(A) == 0 and len(B) == 0:
        break
    
    elif len(A) == 0:
        account += B[0]
        B.popleft()
        
    elif len(B) == 0:
        account += A[0]
        A.popleft()
    
    else:
        if A[0] > B[0]:
            account += B[0]
            B.popleft()
       
        else:
            account += A[0]
            A.popleft()
    
        
print(cnt-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=[0]
b=[0]

ans=0

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

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


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

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

for i in range(n+1):
    for j in range(m, 0, -1):
        time = A[i]+B[j]
        count = i+j
        if time <= k and count > ans:
            ans = count
            break

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

lst = [0]*(M+1)
for i in range(M+1):
    time = 0
    time = sum(A[0:i])
    if time >= K:
        pass
    else:
        for j in range(N):
            time += B[j]
            if time >= K:
                break
        lst[i] = i + j

res = max(lst)
print(res)

Submission status: Wrong Answer

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

ruiseki_a=[]
prev=0
for i in range(n):
    ruiseki_a.append(a[i]+prev)
    prev=ruiseki_a[-1]

ruiseki_b=[]
prev=0
for j in range(m):
    ruiseki_b.append(b[j]+prev)
    prev=ruiseki_b[-1]

j=m-1
ans=0
for l in range(n):
    while j>=0:
        if ruiseki_a[l] + ruiseki_b[j] >k:
            j-=1
            if j<0:
                break
        else:
            break
    if ruiseki_a[l]<k:
        ans=max(ans,(l+1 + j+1))

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
def readinput():
    n,m,k=list(map(int,input().split()))
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    return n,m,k,a,b

def main(n,m,k,a,b):
    qa=deque(a)
    qb=deque(b)
    count=0
    res=k
    while(len(qa)>0 and len(qb)>0):
        if qa[0] < qb[0]:
            res-=qa[0]
            qa.popleft()
        else:
            res-=qb[0]
            qb.popleft()
        if res<0:
            return count
        count+=1
    else:
        if len(qa)==0:
            while(len(qb)>0):
                res-=qb[0]
                qb.popleft()
                if res<0:
                    return count
                count+=1
            return count
        else:
            while(len(qa)>0):
                res-=qa[0]
                qa.popleft()
                if res<0:
                    return count
                count+=1
            return count

import sys
INFTY=sys.maxsize
def find(t,s):
    '''
    単調増加配列sからs[i]がtを超えない最大のiを返す
    '''
    ss=s[:]
    ss.append(INFTY)
    left=0
    right=len(ss)
    while(left<right):
        middle=(left+right)//2
        if ss[middle]==t:
            return middle
        if t<ss[middle]:
            right=middle
        else:
            left=middle+1
    else:
        return left-1

def main2(n,m,k,a,b):
    sa=[0]
    for i in range(1,n+1):
        sa.append(sa[i-1]+a[i-1])
    sb=[0]
    for i in range(1,m+1):
        sb.append(sb[i-1]+b[i-1])
    maxab=0
    for na in range(0,n+1):
        res=k-sa[na]
        if res>0:
            nb=find(res,sb)
            #print(na,nb,sa,sb)
            maxab=max(maxab,na+nb)
    return maxab


def readinput2():
    m=2*10**5
    n=2*10**5
    a=[10**9]*n
    b=[10**9]*m
    k=1
    return n,m,k,a,b

if __name__=='__main__':
    n,m,k,a,b=readinput()
    ans=main2(n,m,k,a,b)
    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()))

lst = [0]*(M+1)
for i in range(M+1):
    time = 0
    time = sum(A[0:i])
    if time >= K:
        pass
    else:
        for j in range(N):
            time += B[j]
            if time >= K:
                break
    lst[i] = i + j

res = max(lst)
print(res)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import sys
import math
import random
from decimal import Decimal


N, M, K = [int(x) for x in stdin.readline().rstrip().split()]
A = list(map(int, input().split()))
A1 = [0]
for i, v in enumerate(A):
    x = A1[i]+v
    A1.append(x)
B = list(map(int, input().split()))
B1 = [0]
for i, v in enumerate(B):
    x = B1[i]+v
    B1.append(x)
c1 = 0
c2 = 0
ans = 0
temp = M

for i in range(N+1):
    for k in range(temp, 0, -1):
        if A1[i]+B1[k] <= K:
            ans = max(ans, i+k)
            temp = k
            break
# print(c1, c2)

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
import bisect

n, m, k = map(int, input().split())
A = [0] + list(map(int,input().split())) # '0'冊目も入れとく
B = [0] + list(map(int,input().split())) # 同上

a = np.cumsum(A) # 'A'の累積
b = np.cumsum(B) # 'B'同上

ans = 0
for i in range(n+1): # 二分探索_方針: A側で読む本の冊数を固定する！
    time = k - a[i] # ↑で固定した時の残り時間
    tmp = bisect.bisect_right(b, time) - 1 # 残りタイム内で読めるB側の本のmax冊数を探索_0冊目とbisect右/左を考慮して'-1'
    ans = max(ans, tmp + 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()))
temp_sum = 0
count = 0
goal = 0
j = 0
i = 0
while True:
    if  A[i] < B[j]:
        temp_sum += A[i]
        if i < len(A) - 1:
            i += 1
    else:
        temp_sum += B[j]
        if j < len(B) - 1:
            j += 1
    if temp_sum > K:
        print(count)
        exit()
    count += 1
print(count + 1)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import sys
import math
import random
from decimal import Decimal


N, M, K = [int(x) for x in stdin.readline().rstrip().split()]
A = list(map(int, input().split()))
A1 = [0]
for i, v in enumerate(A):
    x = A1[i]+v
    A1.append(x)
B = list(map(int, input().split()))
B1 = [0]
for i, v in enumerate(B):
    x = B1[i]+v
    B1.append(x)
c1 = 0
c2 = 0
ans = 0
temp = 0
# print(A1, B1)
for i in range(len(A1)-1, 0, -1):
    if A1[i] <= K:
        c1 = i
        break
for i in range(len(B1)-1, 0, -1):
    if A1[c1]+B1[i] <= K:
        c2 = i
        break
ans = c1+c2
for i in range(c1-1, 0, -1):
    for k in range(c2, len(B1)):
        if A1[i]+B1[k] <= K:
            ans = max(ans, i+k)
        else:
            break
# print(c1, c2)

print(c1+c2)

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

cum_a = []
cum_b = []
c = 0
for a in A:
  c += a
  cum_a.append(c)
c = 0
for b in B:
  c += b
  cum_b.append(c)
ans = 0
for i, a in enumerate(cum_a):
  cnt = 0
  thresh = k-a
  if thresh < 0:
    continue
  for b in cum_b[::-1]:
    if b <= thresh:
      break
    cnt += 1
  cnt = len(B) - cnt
  if ans < cnt + i + 1:
    ans = cnt + i + 1
print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect
N, M, K = map(int, input().split())
*A, = map(int, input().split())
*B, = map(int, input().split())
b = [0] * (M+1)
for i in range(M):
    b[i+1] = b[i] + B[i]
ans = 0
for i in range(1, N+1):
    tmp = K - sum(A[:i])
    if tmp < 0:
        break
    ans = max(ans, i + bisect(b, tmp) - 1)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
#from itertools import zip_longest

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

count = 0
#for a,b in zip_longest(A,B,fillvalue=float(inf)):
#    if a <= b:
#        v.A.pop 

for i in range(N+M):
    if(A[0] < B[0]):
        v = A.popleft()
        K -= v
        if K < 0:
            break
        count += 1
    elif (B[0] < A[0]):
        v = B.popleft()
        K -= v
        if K < 0:
            break
        count += 1

print(count)

Submission status: Wrong Answer

Solution code:
from collections import deque
#from itertools import zip_longest

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

count = 0
#for a,b in zip_longest(A,B,fillvalue=float(inf)):
#    if a <= b:
#        v.A.pop 

for i in range(N+M):
    if(A[0] < B[0]) or (A[0]==B[0] and A[1]<=B[1]):
        v = A.popleft()
        K -= v
        if K < 0:
            break
        count += 1
    elif (B[0] < A[0]) or  (A[0]==B[0] and A[1]>B[1]):
        v = B.popleft()
        K -= v
        if K < 0:
            break
        count += 1

print(count)

Submission status: Wrong Answer

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

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

cum_a = []
cum_b = []
c = 0
for a in A:
  c += a
  cum_a.append(c)
c = 0
for b in B:
  c += b
  cum_b.append(b)
ans = 0
for i, a in enumerate(A):
  cnt = 0
  thresh = k-a
  for b in B:
    if b <= thresh:
      break
    cnt += 1
  cnt = len(B) - cnt
  if ans < cnt + i + 1:
    ans = cnt + i + 1
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
#from itertools import zip_longest

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

count = 0
#for a,b in zip_longest(A,B,fillvalue=float(inf)):
#    if a <= b:
#        v.A.pop 

for i in range(N+M):
    if  A[0] <= B[0]:
        v = A.popleft()
        K -= v
        if K < 0:
            break
        count += 1
    elif B[0] < A[0] :
        v = B.popleft()
        K -= v
        if K < 0:
            break
        count += 1

print(count)

Submission status: Wrong Answer

Solution code:
n, m, time = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
k, kk = 0, 0
c = 0
if time < A[0] and time < B[0]:
    print(0)

if sum(A) + sum(B) <= time:
    print(n+m)

elif sum(A) + sum(B) > time:


    while (time >0):
        if k < n and kk <m:
            if A[k] < B[kk]:

                time -= A[k]
                k += 1


            else:

                time -= B[kk]
                kk += 1


        else:
            if k == n and kk<m:
                time -= B[kk]
                kk +=1

            if kk == m and k<n:
                time -= A[k]
                k += 1
        c += 1

    print(c-1)

Submission status: Wrong Answer

Solution code:
n, m, time = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
k, kk = 0, 0
c = 0
if time < A[0] and time < B[0]:
    print(0)

if sum(A) + sum(B) <= time:
    print(n+m)

elif sum(A) + sum(B) > time:


    while (time >= 0):
        if k < n and kk <m:
            if A[k] < B[kk]:

                time -= A[k]
                k += 1


            else:

                time -= B[kk]
                kk += 1


        else:
            if k == n and kk<m:
                time -= B[kk]
                kk +=1

            if kk == m and k<n:
                time -= A[k]
                k += 1
        c += 1

    print(c-1)

Submission status: Wrong Answer

Solution code:
n, m, time = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
k, kk = 0, 0
c = 0
if time < A[0] and time < B[0]:
    print(0)

if sum(A) + sum(B) <= time:
    print(n+m)

elif sum(A) + sum(B) > time:
    

    while (time >= 0):
        if k < n and kk <m:
            if A[k] < B[kk]:

                time -= A[k]
                k += 1


            else:

                time -= B[kk]
                kk += 1


        else:
            if k == n and kk<m:
                time -= B[kk]
                kk +=1

            if kk == m and k<n:
                time -= A[k]
                k += 1
        c += 1

    print(c)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.insert(0, 0)
b.insert(0, 0)
ans = 0
num_a = n
num_b = 0
flg = True

total_time = sum(a)
if total_time <= k:
    ans = n

for i in range(n+1):
    for j in range(num_b, m):
        if total_time + b[num_b+1] >= k:
            break
        else:
            total_time += b[num_b+1]
            num_b += 1
        if num_a + num_b > ans:
            ans = num_a + num_b
    total_time -= a[num_a]
    num_a -= 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()))
ea=[0]
for i in range(n):
    ea.append(ea[i]+a[i])
eb=[0]
for i in range(m):
    eb.append(eb[i]+b[i])
tb=m
p=0
if n>m:
    ea,eb=eb,ea
    n,m=m,n
for i in range(n+1):
    while ea[i]+eb[tb]>k:
        if tb==0:
            break
        tb-=1
    if ea[i]+eb[tb]<=k:
        p=max(i+tb,p)
print(p)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.insert(0, 0)
b.insert(0, 0)
ans = 0
num_a = n
num_b = 0
flg = True

total_time = sum(a)

for i in range(n+1):
    for j in range(num_b, m):
        if total_time + b[num_b+1] > k:
            break
        else:
            total_time += b[num_b+1]
            num_b += 1
        if num_a + num_b > ans:
            ans = num_a + num_b
    total_time -= a[num_a]
    num_a -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
import math
import collections
from collections import deque 
from functools import reduce

# input = sys.stdin.readline
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
b_max = 0
bi_max = 0
for bi in b:
    if b_max > k:
        b_max -= bi
        bi_max -= 1
        break
    b_max += bi
    bi_max += 1
ti = bi_max
t_max = 0
ai_max = 0
a_max = 0
for ai in a:
    if a_max + ai > k:
        break
    ai_max += 1
    a_max += ai
    for j in range(bi_max, -1, -1):
        if ai_max + bi_max <= k:
            if ai_max + bi_max > ti:
                ti = ai_max + bi_max
            break
        bi_max -= 1
    if ai_max + bi_max > ti:
        ti = ai_max + bi_max
print(ti)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
import math
import collections
from collections import deque 
from functools import reduce

# input = sys.stdin.readline
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
b_max = 0
bi_max = 0
for bi in b:
    if b_max > k:
        b_max -= bi
        bi_max -= 1
        break
    b_max += bi
    bi_max += 1
ti = bi_max
t_max = 0
ai_max = 0
a_max = 0
for ai in a:
    if a_max + ai > k:
        break
    ai_max += 1
    a_max += ai
    for j in range(bi_max, 0, -1):
        if ai_max + bi_max <= k:
            if ai_max + bi_max > ti:
                ti = ai_max + bi_max
            break
        bi_max -= 1
    if ai_max + bi_max > ti:
        ti = ai_max + bi_max
print(ti)

Submission status: Wrong Answer

Solution code:
n,m,l = map(int,input().split(" "))
Ns = input().split(" ")
N = [int (n) for n in Ns]
Ms = input().split(" ")
M = [int(n) for n in Ms]
#print(n,m,l)
#print(N,M)
i = 0
j = 0
total = 0
cnt = 0
while total < l:
  #print(i,j,total,cnt)
  if  i == n and j == m:
    break
  elif i < n and j == m:
    if total + N[i] <= l:
      total = total + N[i]
      i = i+1
      cnt = cnt + 1
    else:
      break
  elif i == n and j < m:
    if total + M[j] <= l:
      total = total + M[j]
      j = j+1
      cnt = cnt +1
    else:
      break
  elif i < n and j < m and (total+N[i] <= l or total+M[j] <= l):
    if N[i] <= M[j]:
      total = total + N[i]
      i = i+1
      cnt = cnt +1
    elif N[i] > M[j]:
      total = total + M[j]
      j = j+1
      cnt = cnt +1
  else:
    break
print(cnt)#,i,j,total,n,m,l)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce, lru_cache  # @lru_cache(None)
from fractions import gcd
import sys  # def input(): return sys.stdin.readline().rstrip() # sys.setrecursionlimit(10**6)

n, m, k = (int(x) for x in input().split())
A = list(int(x) for x in input().split())
B = list(int(x) for x in input().split())

accA = list(accumulate(A))
accB = list(accumulate(B))
ans = 0
for i in range(n):
    if accA[i] > k:
        break
    ans = max(ans, i + 1 + bisect_right(accB, k - accA[i]))
else:
    ans = max(ans, 0 + bisect_right(accB, k))
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce, lru_cache  # @lru_cache(None)
from fractions import gcd
import sys  # def input(): return sys.stdin.readline().rstrip() # sys.setrecursionlimit(10**6)

n, m, k = (int(x) for x in input().split())
A = list(int(x) for x in input().split())
B = list(int(x) for x in input().split())

accA = list(accumulate(A))
accB = list(accumulate(B))
ans = 0
for i in range(n):
    if accA[i] > k:
        break
    ans = max(ans, i + 1 + bisect_right(accB, k - accA[i]))
else:
    ans = max(ans, n + bisect_right(accB, k - accA[n-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
c = []
for _ in range(n + m):
    if A > n - 1:
        c.extend(b[B:])
        break
    elif B > m - 1:
        c.extend(a[A:])
        break
    if a[A] > b[B]:
        c.append(b[B])
        B += 1
    else:
        c.append(a[A])
        A += 1
import bisect as bi
s = [0] * (n + m + 1)
for i in range(n + m):
    s[i + 1] = s[i] + c[i]
s.pop(0)
#print(c)
#print(s)
print(bi.bisect_right(s,k))

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
c = []
for _ in range(n + m):
    if A > n - 1:
        c.extend(b)
        break
    elif B > m - 1:
        c.extend(a)
        break
    if a[A] > b[B]:
        c.append(b[B])
        B += 1
    else:
        c.append(a[A])
        A += 1
import bisect as bi
s = [0] * (n + m + 1)
for i in range(n + m):
    s[i + 1] = s[i] + c[i]
print(bi.bisect_left(s,k)-1)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
import math
import collections
from collections import deque 
from functools import reduce

# input = sys.stdin.readline
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
b_max = 0
bi_max = 0
for bi in b:
    if b_max > k:
        b_max -= bi
        bi_max -= 1
        break
    b_max += bi
    bi_max += 1
ti = bi_max
t_max = 0
ai_max = 0
a_max = 0
for ai in a:
    if a_max + ai > k:
        break
    ai_max += 1
    a_max += ai
    for j in range(bi_max, 0, -1):
        if ai_max + bi_max <= k:
            if ai_max + bi_max > ti:
                ti = ai_max + bi_max
            break
        bi_max -= 1
print(ti)

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()))
'''
with open('./b09.txt') as f:
    N, M, K = map(int, f.readline().split())
    A = list(map(int, f.readline().split()))
    B = list(map(int, f.readline().split()))
'''

ans = 0
nowK = K
for A_idx in range(N):
    if nowK < A[A_idx]:
        break
    ans += 1
    nowK -= A[A_idx]
for B_idx in range(M):
    if nowK < B[B_idx]:
        break
    ans += 1
    nowK -= B[B_idx]
tmp_ans = ans
finish = False
for i in range(A_idx, -1, -1):
    nowK += A[i]
    tmp_ans -= 1
    for j in range(B_idx, M):
        if finish or nowK < B[j]:
            break
        nowK -= B[j]
        tmp_ans += 1
        if j == M - 1:
            finish = True
    B_idx = j
    ans = max(tmp_ans, ans)
print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

SA, SB = [0], [0]

for i in range(n):
    SA.append(SA[-1] + A[i])
for i in range(m):
    SB.append(SB[-1] + B[i])

res = bisect_left(SA, k) - 1

for i, sa in enumerate(SA):
    for sb in SB:
        tmp = i + bisect_left(SB, k - sa) - 1
        res = max(res, tmp)
print(res)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a, b = iter(A), iter(B)
now_a, now_b = next(a), next(b)
ans, cnt_time = 1, 0
ex_a = True
ex_b = True
while cnt_time < K:
    #print(ans)
    if now_a > now_b and ex_b:
        try:
            ans += 1
            cnt_time += now_b
            #print('b', now_b, cnt_time)
            now_b = next(b)
        except StopIteration:
            ex_b = False
            continue
    elif now_a <= now_b and ex_a:
        try:
            ans += 1
            cnt_time += now_a
            #print('a', now_a, cnt_time)
            now_a = next(a)
        except StopIteration:
            ex_a = False
            continue
    elif ex_b:
        try:
            ans += 1
            cnt_time += now_b
            #print('b2', now_b, cnt_time)
            now_b = next(b)
        except StopIteration:
            ex_b = False
            continue
    elif ex_a:
        try:
            ans += 1
            cnt_time += now_a
            #print('a2', now_a, cnt_time)
            now_a = next(a)
        except StopIteration:
            ex_a = False
            continue

print(ans-1)

Submission status: Wrong Answer

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


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

a, b = iter(A), iter(B)
now_a, now_b = next(a), next(b)
ans, cnt_time = 0, 0
ex_a = True
ex_b = True
while cnt_time < K:
    ans += 1
    #print(ans)
    try:
        if now_a > now_b and ex_b:
            try:
                cnt_time += now_b
                #print('b', now_b, cnt_time)
                now_b = next(b)
            except StopIteration:
                ex_b = False
                continue
        elif now_a <= now_b and ex_a:
            try:
                cnt_time += now_a
                #print('a', now_a, cnt_time)
                now_a = next(a)
            except StopIteration:
                ex_a = False
                continue
        elif ex_b:
            cnt_time += now_b
            #print('b', now_b, cnt_time)
            now_b = next(b)
        elif ex_a:
            cnt_time += now_a
            #print('a', now_a, cnt_time)
            now_a = next(a)
    except StopIteration:
        ans += 1
        break

print(ans-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,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)
print(b)

totaltime = 0
count,j = 0, M

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

print(count)

Submission status: Wrong Answer

Solution code:
import itertools
def main():
    n,m,k=map(int, input().split())
    a=[int(i) for i in input().split()]
    b=[int(i) for i in input().split()]

    ia = n-1
    res = n
    ib = 0
    time = sum(a)

    while(ia>=0 and ib<m):
        if(time > k):
            time -= (a[ia])
            res-=1
            ia-=1

        elif(time+b[ib]<=k):
            time += (b[ib])
            res+=1
            ib+=1
        else:
            break

    print(res)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from sys import stdin
import bisect

def main():
    input = stdin.readline
    n, m, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    c = [0] * (n + 1)
    for i in range(n):
        c[i + 1] = c[i] + a[i]
    d = [0] * (m + 1)
    for i in range(m):
        d[i + 1] = d[i] + b[i]
    cnt = 0
    for i in range(n + 1):
        if c[i] > k:
            break
        e = bisect.bisect_left(d, k - c[i])
        if e == m and cnt < i + m:
            cnt = i + m
        if e < m and cnt < i + e - 1:
            cnt = i + e - 1
    print(cnt)
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()))
asum = 0
maxtemp = 0
bj = m
bsum = sum(b)
for i in range(n):
    if(asum >k):
        temp = i-1
        if(maxtemp < temp):
            maxtemp = temp
        break
    for j in range(bj):
        if(asum + bsum <= k):
            bj = bj - j
            temp = i + bj
            break
        bsum -= b[bj-1 - j]
    else:
        bj = 0
        temp = i
    if(maxtemp < temp):
        maxtemp = temp
        print(maxtemp)
    asum +=a[i]
for j in range(bj):
    if(asum + bsum <= k):
        bj = bj - j
        temp = n + bj
        break
    bsum -= b[bj-1 - j]
else:
    if(asum <= k):
        temp = n
if(maxtemp < temp):
    maxtemp = temp
print(maxtemp)

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()))
asum = 0
maxtemp = 0
bj = m
bsum = sum(b)
for i in range(n):
    for j in range(bj):
        if(asum + bsum <= k):
            bj = bj - j
            temp = i + bj
            break
        bsum -= b[bj-1 - j]
    else:
        temp = i
    if(maxtemp < temp):
        maxtemp = temp
    asum +=a[i]
for j in range(bj):
    if(asum + bsum <= k):
        bj = bj - j
        temp = n + bj
        break
    bsum -= b[bj-1 - j]
else:
    temp = n
if(maxtemp < temp):
    maxtemp = temp
print(maxtemp)

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()))
asum = 0
maxtemp = 0
bj = m
bsum = sum(b)
for i in range(n):   
    if(asum >k):
        temp = i-1
        if(maxtemp < temp):
            maxtemp = temp
        break
    for j in range(bj):
        if(asum + bsum <= k):
            bj = bj - j
            temp = i + bj
            break
        bsum -= b[bj-1 - j]
    else:
        temp = i
    if(maxtemp < temp):
        maxtemp = temp
    asum +=a[i]
if(asum + bsum <= k):
    maxtemp = n + bj
print(maxtemp)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
A = tuple(map(int, input().split()))
B = tuple(map(int, input().split()))
if sum(A) + sum(B) <= k:
    print(len(A)+len(B))
else:
    from itertools import accumulate
    AS = [0] + list(accumulate(A))
    BS = [0] + list(accumulate(B))

    from bisect import bisect_left
    ans = 0
    for i in range(n+1):
        if AS[i] > k:
            break
        ans = max(ans, bisect_left(BS, k - AS[i])-1+i)

    print(ans)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
A = tuple(map(int, input().split()))
B = tuple(map(int, input().split()))
if sum(A) + sum(B) <= k:
    print(len(A)+len(B))
else:
    from itertools import accumulate
    import numpy as np
    AS = [0] + list(accumulate(A))
    BS = np.array(list(accumulate(B)))

    from bisect import bisect_left
    ans = 0
    for i in range(n+1):
        if AS[i] > k:
            break
        ans = max(ans, bisect_left(BS, k - AS[i])+i)

    print(ans)