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 = list(map(int,input().split()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))

time = 0
count = 0
a_i = 0
b_i = 0

# if sum(a) + sum(b) <= k:
#     print(len(a)+ len(b))
#     exit()

for _ in range(n+m):
    tmp = 0
    if a_i <= len(a)-1 and b_i <= len(b)-1:
        av = a[a_i]
        bv = b[b_i]
        if av <= bv:
            time += av
            tmp = av
            a_i += 1

        elif av > bv:
            time += bv
            b_i += 1
            tmp = bv
        count += 1
    else:
        if a_i > len(a)-1:
            bv = b[b_i]
            time += bv
            tmp = bv
            b_i += 1
        elif b_i > len(b)-1:
            av = a[a_i]
            time += av
            tmp = av
            a_i += 1
        count += 1
    if time > k:
        time -= tmp
        count -= 1
        break
print(count)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int, input().split())
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
a.append(10**10)
b.append(10**10)
cnt_a=0
cnt_b=0
while True:
    if a[cnt_a] < b[cnt_b]:
        if k > a[cnt_a]:
            k -= a[cnt_a]
            cnt_a += 1
        else:
            break
    else:
        if k > b[cnt_b]:
            k -= b[cnt_b]
            cnt_b += 1
        else:
            break
print(cnt_a + cnt_b)

Submission status: Wrong Answer

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

ans=0
a_now=-1
b_now=m-1
num_a=0
num_b=sum(b)

while b_now>=0 and a_now<n:
    if (num_a+num_b<=k):
        ans=max(ans,a_now+b_now+2)
        a_now+=1
        if (a_now==n):
          break
        num_a+=a[a_now]
    else:
        b_now-=1
        if (b_now==-1):
          break
        num_b-=b[b_now+1]
   
  
  
a_now=n-1
b_now=-1
num_a=sum(a)
num_b=0
while b_now>=0 and a_now<n:
    if (num_a+num_b<=k):
        ans=max(ans,a_now+b_now+2)
        b_now+=1
        if (b_now==m):
          break
        num_b+=b[b_now]
    else:
        a_now-=1
        if (a_now==-1):
          break
        num_a-=a[a_now+1]
    
print(ans)

Submission status: Wrong Answer

Solution code:

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





if A_lis[0]>B_lis[0]:
    status=B_lis[0]
elif  A_lis[0]<B_lis[0]:
    status=A_lis[0]
else:
    status=A_lis[0]
    
    

count=0



for i in range(len(A_lis)+len(B_lis)):
    if K>status:
        if len(A_lis)>0 and len(B_lis)>0:
            if A_lis[0]<B_lis[0]:
                pd=A_lis.pop(0)
                status+=pd
                count+=1
            elif A_lis[0]>B_lis[0]:
                pd=B_lis.pop(0)
                status+=pd
                count+=1
            elif A_lis[0]==B_lis[0]:
                pd=A_lis.pop(0)
                status+=pd
                count+=1
        elif len(A_lis)==0:
            pd=B_lis.pop(0)
            status+=pd
            count+=1
        elif len(B_lis)==0:
            pd=A_lis.pop(0)
            status+=pd
            count+=1
print(str(count))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)

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

    pre_A = [0] * N
    pre_B = [0] * M
    pre_A[0] = A[0]
    pre_B[0] = B[0]

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

    ans = 0

    for i in range(N):
        for j in range(M):
            if pre_A[i] + pre_B[j] <= K:
                ans = max(ans,i+j+2)
            else:
                break

    return ans

if __name__ == "__main__":
    print(main())

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()]
a.reverse() #tle?
b.reverse()
cont = 0
while len(a) > 0 and len(b)>0:
    if a[-1] < b[-1]:
        k-=a.pop()
        if k<0: break
        cont+=1
    else:
        k-=b.pop()
        if k<0: break
        cont+=1
    #print(k,a,b)

while len(a) > 0 and k > 0:
    k-=a.pop()
    if k>=0: cont+=1
while len(b) > 0 and k > 0:
    k-=b.pop()
    if k>=0: cont+=1
    

print(cont)

Submission status: Wrong Answer

Solution code:
def go(s,b):
    count=-1
    for i in b:
        if s>=i:
           count+=1

    return count

n,m,k= map(int,input().split(" "))

a= (map(int,input().split(" ")))
b= (map(int,input().split(" ")))

c,d=[],[]
s=0
for i in a:
   s+=i
   c.append(s)
s=0
for i in b:
   s+=i
   d.append(s)

mx=0
for j in range(len(c)):
    if c[j]<=k:
        r=go(k-c[j],d)
        if r+1+j+1>mx:
            mx=r+j+2
print(mx)

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
CT = len(A) + len(B)
AFLG = 0
BFLG = 0
Time = 0
AT = 0
BT = 0

while CT>0:
  if AFLG >len(A)-1:
    AT = 10000000000
  else:
    AT = A[AFLG]

  if BFLG >len(B)-1:
    BT = 10000000000
  else:
    BT = B[BFLG]
    
  if AT <= BT:
    Time = AT
    AFLG +=1
  else:
    Time = BT
    BFLG +=1
  
  if K-Time>=0:
    K -= Time
    Ans +=1
  else:
    break
  
  CT -=1
  
print(Ans)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
INF = int(1e18)
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A = A[:]
B = B[:]
i, j = 0, 0
mcnt = 0
tmp = M+1
ccnt = 0
while tmp != 0:
  ccnt += 1
  tmp //= 2
LA = [0 for _ in range(N+1)]
LB = [0 for _ in range(M+1)]
for i in range(N):
  LA[i+1] = LA[i] + A[i]
for i in range(M):
  LB[i+1] = LB[i] + B[i]
for i in range(N+1):
  l, r = 0, M+1
  d = (l + r) // 2
  if LA[i] <= K:
    if LB[M] + LA[i] <= K:
      mcnt = max(i + M, mcnt)
    else:
      for j in range(ccnt + 1):
        if LB[d] + LA[i] <= K:
          l = d
          d = (l + r) // 2
        else:
          r = d
          d = (l + r) // 2
      print(d)
      mcnt = max(i + d, mcnt)
  else:
    break
print(mcnt)

Submission status: Wrong Answer

Solution code:
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
A.append(10**9+1)
B.append(10**9+1)
ans=0
time=0
while K>time:
    if time+min(A[0],B[0])>K:
        break
    ans+=1
    if A[0]>B[0]:
        a=B.pop(0)
        time+=a
    else:
        a=A.pop(0)
        time+=a
    if ans==N+M:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
n,m,k = map(int,input().split())
a = input().split(" ")
lista = [int(n) for n in a]
b = input().split(" ")
listb = [int(n) for n in b]
time = 0
count = 0
while k>time:
  if (len(lista)>0 and len(listb)>0 and lista[0]>=listb[0]) or (len(listb)>0 and len(lista)==0):
    time+=listb.pop(0)
    if time>k:
      break
    else:
      count+=1  
  elif (len(lista)>0 and len(listb)>0 and listb[0]>=lista[0]) or (len(lista)>0 and len(listb)==0):
    time+=lista.pop(0)
    if time>k:
      break
    else:
      count+=1
  else:
    break
print(count)

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

aa = list(accumulate(a))
ab = list(accumulate(b))

a_i = bisect.bisect_left(aa, k+1)
b_i = bisect.bisect_left(ab, k+1)

a_l = len(aa[:a_i])
b_l = len(ab[:b_i])

ans = 0
for i, an in enumerate(aa[:a_i]):
    for j, bn in enumerate(ab[:b_i]):
        if an+bn <= k:
            ans = i + j + 2

print(ans)

Submission status: Wrong Answer

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

from pprint import pprint
import math
import sys

sys.setrecursionlimit(10 ** 6)
INF = float('inf')


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


count = 0
time = 0
i_a = 0
i_b = 0
while True:
    if i_a > N - 1 and i_b > M - 1:
        break
    elif i_a > N - 1 and i_b <= M - 1:
        if time + B[i_b] <= K:
            count += 1
            time += B[i_b]
            i_b += 1
        else:
            break
    elif i_b > M - 1 and i_a <= N - 1:
        if time + A[i_a] <= K:
            count += 1
            time += A[i_a]
            i_a += 1
        else:
            break
    else:
        if A[i_a] >= B[i_b]:
            if time + B[i_b] <= K:
                count += 1
                time += B[i_b]
                i_b += 1
            else:
                break
        else:
            if time + A[i_a] <= K:
                count += 1
                time += A[i_a]
                i_a += 1
            else:
                break

print(count)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate as ia 
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a = list(ia(A))
b = list(ia(B))
na = 0
nb = 0
for i in a:
  if i <= K:
    na += 1
  else:
    break
for i in b:
  if i <= K:
    nb += 1
  else:
    break
#print(na, nb)
t = a[na-1]
for i in B:
  if t + i > K:
    break
  else:
    na += 1
    t += i
t = b[nb-1]
for i in A:
  if t + i > K:
    break
  else:
    nb += 1
    t += i
print(max(na, nb))

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(N, M, K)
# print(A)
# print(B)
t = 0
n_book = 0

while True:
    if len(A) != 0:
        top_a = A[0]
    else:
        top_a = 10**6
    if len(B) != 0:
        top_b = B[0]
    else:
        top_b = 10**6
    if top_a <= top_b:
        if t + top_a <= K:
            t += A.pop(0)
            n_book += 1
        else:
            print(n_book)
            exit()
    else:
        if t + top_b <= K:
            t += B.pop(0)
            n_book += 1
        else:
            print(n_book)
            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()))

# aをi冊読む
sum_a = [0]*n
sum_b = [0]*m
sum_a[0] = a[0]
sum_b[0] = b[0]
for i in range(1, n):
    sum_a[i] = sum_a[i-1]+a[i]
for i in range(1, m):
    sum_b[i] = sum_b[i-1]+b[i]

def binary_search(list, item):
    low = 0
    high = len(list) - 1
    if list[high] < item:
        return high
    if list[low] > item:
        return low
    while low <= high:
        mid = (low + high) //2
        guess = list[mid]
        if high == low:
            return low
        # if guess == item:
            # return mid
        if guess > item:
            high = mid -1
        else:
            low = mid + 1
    return low-1

ans = 0
for i in range(n):
    tmp_ans = i+1
    tmp_k = k-sum_a[i]
    if tmp_k <= 0:
        pass
    else:
        b_index = binary_search(sum_b, tmp_k)
        tmp_ans += b_index+1
        if tmp_ans > ans:
            ans = tmp_ans

tmp_ans = 0
if sum_b[0] < k:
    tmp_ans = binary_search(sum_b, k)+1
if tmp_ans > ans:
    ans = tmp_ans
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()))

read = 0
i, j = 0, 0
flag = True
while(i<len(a) and j<len(b)):
    if a[i] < b[j]:
        flag = True
    elif a[i] == b[j]:
        q, p = 0, 0
        while((q+i)<len(a) and (p+j)<len(b)):
            if a[q+i] < b[p+j]:
                flag = True
                break
            elif a[q+i] > b[p+j]:
                flag = False
                break
            q += 1
            p += 1
    else:
        flag = False

    if flag:
        k -= a[i]
        i += 1
    else:
        k -= b[j]
        j += 1
    if k<0:
        break
    read += 1

if k > 0:
    if i==len(a):
        while(j < len(b)):
            k -= b[j]
            j += 1
            if k<0:
                break
            read += 1
    elif j==len(b):
        while(i < len(a)):
            k -= a[i]
            i += 1
            if k<0:
                break
            read += 1

print(read)

Submission status: Wrong Answer

Solution code:
n,m,k = map(int, input().split())
la = list(map(int, input().split()))
lb = list(map(int, input().split()))
lt = []
x = 0
a_max = 0
t = 0
for i in range(n):
  t += la[i]
  if t >= k:
    a_max = i-1
    t -= la[i]
    x = i
    lt.append(x)
    break
  if i == n-1:
    x = i+1
    lt.append(x)

j = 0
for i in range(m):
  t += lb[i]
  x += 1
  if t > k:
    lt.append(x-1)
    if j <= a_max:
      t -= la[a_max-j]
      x -= 1
      j += 1
    else:
      break
  if i == m-1:
    lt.append(x)

print(max(lt))

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
import sys
import bisect
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
l=[]
for A,B in zip(a,b):
    l.append(min(A,B))
    l.append(max(A,B))
if len(a)>len(b):
    l.extend(a[-(len(a)-len(b)):])
if len(b)>len(a):
    l.extend(b[-(len(b)-len(a)):])
cumsum=list(accumulate(l))
print(bisect.bisect_right(cumsum,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()))

l = a + b
l.sort()
t = 0
ans = 0
for i in l:
    t += i
    if k >= t:
        ans += 1
    else:
        break
print(ans)

Submission status: Wrong Answer

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

#print(a)
#print(b)
sum_time = 0
sum_time_a = 0
sum_time_b = 0
nn = 0
#print(b[nn])
num_books = 0
while sum_time <= k:
    if a == [] and b == []:
        num_books += 1
        break
    elif a == []:
        sum_time += b[0]
        b.pop(0)
        num_books += 1
        #print(num_books)
    elif b == []:
        sum_time += a[0]
        a.pop(0)
        num_books += 1
        #print(num_books)
    elif a[0] > b[0]:
        sum_time += b[0]
        b.pop(0)
        num_books += 1
        #print(num_books)
    elif a[0] < b[0]:
        sum_time += a[0]
        a.pop(0)
        num_books += 1
        #print(num_books)
    else:
        while sum_time_a == sum_time_b and len(a) > nn and len(b) > nn:
            sum_time_a += a[nn]
            sum_time_b += b[nn]
            nn += 1
        nn = 0
        if sum_time_a > sum_time_b:
            sum_time += b[0]
            b.pop(0)
            num_books += 1
        else:
            sum_time += a[0]
            a.pop(0)
            num_books += 1
        sum_time_a = 0
        sum_time_b = 0
print(num_books-1)

Submission status: Wrong Answer

Solution code:
def whichDesk(a, b):
    if len(a) == 0:
        return 2
    elif len(b) == 0:
        return 1
    elif a[0] >= b[0]:
        return 2
    elif a[0] < b[0]:
        return 1

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

t = 0
cnt = 0

while t <= k and (len(a) > 0 or len(b) > 0):
    if whichDesk(a, b) == 2:
        t += b[0]
        b.pop(0)
    else:
        t += a[0]
        a.pop(0)
    if t <= k:
        cnt += 1

print(cnt)

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

cost = 0
cnt = 0

top_a = a.pop(0)
top_b = b.pop(0)

while True:
    cnt +=1

    if top_a > top_b:
        cost += top_b
        if len(b) != 0:
            top_b = b.pop(0)
        else:
            top_b = np.inf
    else:
        cost += top_a
        if len(a) != 0:
            top_a = a.pop(0)
        else:
            top_a = np.inf

    if top_a == np.inf and top_b == np.inf:
        break

    if cost > k:
        cnt -= 1
        break

print(cnt)

Submission status: Wrong Answer

Solution code:
import sys
N, M, K = map(int,input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]

A.append(10**10)
B.append(10**10)

#print(A)
#print(B)
time = 0
ans = 0

i, j = 0, 0
if int(A[0]+0.5)>int(K+0.5) and int(B[0]+0.5)>int(K+0.5):
    print(0)
    sys.exit()
else:
    for _ in range(len(A)+len(B)-2):
        if A[i] <=B[j]:
            time += A[i]
            if time <= K:
                ans += 1
                i += 1
            else:
                break
        elif A[i] > B[j]:
            time += B[j]
            if time <= K:
                ans += 1
                j += 1
            else:
                break
        #print(i,j,time)
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
i = 0
j = 0
count = 0

while time <= k:
    if i == len(a) and j == len(b):
        time += k
    elif i == len(a):
        time += b[j]
        if time > k:
            break
        j += 1
        count += 1
    elif j == len(b):
        time += a[i]
        if time > k:
            break
        i += 1
        count += 1
    elif a[i] <= b[j]:
        time += a[i]
        if time > k:
            break
        i += 1
        count += 1
    elif a[i] > b[j]:
        time += b[j]
        if time > k:
            break
        j += 1
        count += 1
"""
    elif a[i] == b[j]:
        if a[i+1] > b[j+1]:
            time += b[j]
            if time > k:
                break
            j += 1
            count += 1
        elif a[i+1] < b[j+1]:
            time += a[i]
            if time > k:
                break
            i += 1
            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()))
ans=K
i=0
j=0
while ans>0:
    if i==N:
        ans=ans-B[j]
        j=j+1
        continue
    if j==M:
        ans=ans-A[i]
        i=i+1
        continue 
    if A[i]>=B[j]:
        ans=ans-B[j]
        j=j+1
    elif A[i]<B[j]:
        ans=ans-A[i]
        i=i+1
    
print(i+j)

Submission status: Wrong Answer

Solution code:
def main():
    N,M,K = map(int,input().split())
    A = []*N
    B = []*M
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))
    ans = [10**9+10]* (N+M)
    A2 = [0] * N
    B2 = [0] * M
    cnt = 0
    for i in range(N):
        if A[i] + A2[i-1] > K:
            break
        A2[i] = A[i] + A2[i-1]
        cnt += 1
    for i in range(M):
        B2[i] = B[i] + B2[i-1]
    MAX = cnt
    for i in reversed(range(cnt)):
        cnt_m = 0
        for j in range((MAX-cnt),M):
            if A2[i] + B2[j] > K:
                break
            cnt_m += 1
        if MAX < cnt_m + i + 1:
            MAX = cnt_m + i + 1
    print(MAX)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import deque

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

q = deque()
q.append([0,0,0])#(time,a,b)
r = 0
k = 0

while len(q) > 0:
  time,a,b = q.popleft()
  
  r = max(r,a+b)
    
  
  if a<N:
    if k == [a+1,b]:
      continue
    if Ali[a] <= K-time:
      q.append([time+Ali[a],a+1,b])
    
  if b<M:
    if Bli[b] <= K-time:
      q.append([time+Bli[b],a,b+1])
    
  k = [a,b+1]
    
print(r)

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_depth = 0
tmp = 0
for i in range(n):
    if tmp+a[i] <= k:
        tmp += a[i]
        a_depth += 1
    else:
        break
b_depth = 0
tmp = 0
for i in range(m):
    if tmp+b[i] <= k:
        tmp += b[i]
        b_depth += 1
    else:
        break

ans = 0
total = 0
tmp_ans = 0

for i in range(a_depth):
    total = 0
    tmp_ans = 0

    for j in range(a_depth-i):
        if total+a[j] <= k:
            total += a[j]
            tmp_ans += 1
        else:
            break
    
    for j in range(b_depth):
        if total+b[j] <= k:
            total += b[j]
            tmp_ans += 1
        else:
            break
        
    ans = max(ans, tmp_ans)

print(ans)

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)):
    if A1[i] > K:
        break
    for k in range(len(B1)):
        if B1[k] > K:
            break
        if A1[i]+B1[k] <= K:
            if i+k > ans:
                ans = i+k
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(rs())
def rs_(): return [_ for _ in rs().split()]
def ri_(): return [int(_) for _ in rs().split()]

N, M, K = ri_()
A = ri_()
B = ri_()
C = A + B
C.sort()
ans = 0
for i in range(len(C)):
    K -= C[i]
    if K >= 0:
        ans += 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()))
i = 0
n = 0
while i <= K:
    if a == [] and b == []:
        n += 1
        break
    elif a == []:
        i += b[0]
        del b[0]
        n += 1

    elif b == []:
        i += a[0]
        del a[0]
        n += 1

    elif a[0] < b[0]:
        i += a[0]
        del a[0]
        n += 1

    else:
        i += b[0]
        del b[0]
        n += 1
print(n -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()))

MAX = 10 ** 18

# 累積和
accA, accB = [0] * (n + 1), [0] * (m + 1)
accA[1], accB[1] = A[0], B[0]
for i in range(2, n + 1):
    accA[i] = accA[i - 1] + A[i - 1]
for i in range(2, m + 1):
    accB[i] = accB[i - 1] + B[i - 1]
accA.append(MAX)
accB.append(MAX)

from bisect import bisect_left
idxA = bisect_left(accA, k) - 1
idxB = bisect_left(accB, k) - 1

# Aを固定
sub = accA[idxA]
i = idxB
while True:
    if sub + accB[i] <= k:
        break
    i -= 1

# Bを固定
sub = accB[idxB]
j = idxA
while True:
    if sub + accA[j] <= k:
        break
    j -= 1

print(max(idxA + i, idxB + 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.append(10**9 + 1)
B.append(10**9 + 1)
ans = 0
i = 0
j = 0

while K >= 0:
  if min(A[i],B[j]) <= K:
    ans += 1
    if A[i] > B[j]:
      K = K - B[j]
      j += 1
    elif B[j] > A[i]:
      K = K- A[i]
      i += 1
    elif A[i] == B[j]:
      k = 1
      while A[i+k] > B[j+k] or A[i+k] < B[j+k]:
        k += 1
      if A[i+k] > B[j+k]:
        K = K - B[j]
        j += 1
      elif A[i+k] < B[j+k]:
        K = K - A[i]
        i += 1
  else:
    break
print(ans)

Submission status: Wrong Answer

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

l = []
nn, mm = 0, 0
for i in range(n+m):
  if n == nn:
    l.append(b[mm])
    mm+=1
  elif m == mm:
    l.append(a[nn])
    nn += 1
  else:
    l.append(min(a[nn], b[mm]))
    if a[nn] <= b[mm]:
      nn += 1
    elif a[nn] > b[mm]:
      mm += 1

total = 0
cnt = 0
for i in range(n+m):
  if total+l[i] > k:
    break
  total += l[i]
  cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import deque

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

time_count = 0
count = 0
while True:
    if A:
        a = A.popleft()
    if B:
        b = B.popleft()

    if a <= b:
        time_count += a
        count += 1
        B.appendleft(b)
        if time_count > K:
            time_count -= a
            count -= 1
            break
    else:
        time_count += b
        count += 1
        A.appendleft(a)
        if time_count > K:
            time_count -= b
            count -= 1
            break 
    
print(count)

Submission status: Wrong Answer

Solution code:
import math
#map(int,input().split())
#int(x) for x in input().split()
#for _ in range(int(input())):
n,m,k=map(int,input().split())
a=[int(x) for x in input().split()]
b=[int(x) for x in input().split()]
pa=[0]*n
pb=[0]*m
pa[0]=a[0]
pb[0]=b[0]
for i in range(1,n):
	pa[i]=pa[i-1]+a[i]
for i in range(1,m):
	pb[i]=pb[i-1]+b[i]

i=n-1
j=m-1
ans=0
while i>=0:
	if ans>=i+1+i+1:
		break
	if pa[i]>k:
		i-=1
		continue
	j=m-1
	while j>=0:
		if ans>=i+1+j+1:
			break
		if pa[i]+pb[j]<=k:
			ans=max(ans,i+1+j+1)
			break
		else:
			j-=1
	i-=1

j=m-1
while j>=0:
	if ans>=j+1+j+1:
		break
	if pb[j]>k:
		j-=1
		continue
	i=n-1
	while i>=0:
		if ans>=i+1+j+1:
			break
		if pa[i]+pb[j]<=k:
			ans=max(ans,i+1+j+1)
			break
		else:
			i-=1
	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()))
count = 0
while K > 0:
    if A == []:
        K -= B.pop(0)
    elif B == []:
        K -= A.pop(0)
    else:
        if A[0] >= B[0]:
            K -= B.pop(0)
        else:
            K -= A.pop(0)
    if K >= 0:
        count += 1
print(count)

Submission status: Wrong Answer

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

rest = K
ans = 0

def dfs(cost, aindex, bindex, score):

    if K == cost:
        print("1:", score, cost)
        return score
    elif K < cost:
        print("2:", score, cost)
        return score - 1
    
    if aindex == N and bindex == M:
        print("3:", score, cost)
        return score

    elif aindex >= N:
        return dfs(cost + B[bindex], aindex, bindex+1, score + 1)
    
    elif bindex >= M:
        return dfs(cost + A[aindex], aindex+1, bindex, score + 1)

    else:
        return max(dfs(cost + A[aindex], aindex+1, bindex, score + 1), dfs(cost + B[bindex], aindex, bindex + 1, score + 1))

print(max(dfs(A[0], 1, 0, 1), dfs(B[0], 0, 1, 1)))

Submission status: Wrong Answer

Solution code:
from collections import deque
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = N + M
cnt = 0
res = 0
A = deque(A)
B = deque(B)
for c in range(C):
    if A:
        a = A.popleft()
    else:
        a = 10**10+1
    if B:
        b = B.popleft()
    else:
        b = 10**10+1
    if a >= b:
        cnt += b
        A.appendleft(a)
    elif a <= b:
        cnt += a
        B.appendleft(b)

    if cnt < K:
        res += 1
    else:
        break

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
pa = abs(N-M) + 1
A = list(map(int, input().split()))+ [1000000010]
B = list(map(int, input().split()))+ [1000000010]
c = 0
while K >= A[0] or K >= B[0]:
    if A[0] < B[0]:
        K -= A.pop(0)
    else:
        K -= B.pop(0)
    c += 1
print(c)

Submission status: Wrong Answer

Solution code:
from collections import deque
from itertools import accumulate

n, m, k = list(map(int, input().split()))
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))

a_sum_list = list(accumulate(a_list))
b_sum_list = list(accumulate(b_list))

# print(a_sum_list)
# print(b_sum_list)

a_queue = deque(a_sum_list)
b_queue = deque(b_sum_list)

min_len = min(len(a_sum_list), len(b_sum_list))
# len_a = len(a_sum_list)
# len_b = len(b_sum_list)
BIG_NUM = 1e20
a_time = 0
b_time = 0
ans = 0
time = 0
while time <= k:
    a_0 = a_queue[0] if len(a_queue) != 0 else BIG_NUM
    b_0 = b_queue[0] if len(b_queue) != 0 else BIG_NUM
    if a_0 == BIG_NUM and b_0 == BIG_NUM:
        print(ans)
        exit()
    if a_0 <= b_0:
        a = a_queue.popleft()
        a_time = a
    else:
        b = b_queue.popleft()
        b_time = b
    time = a_time + b_time
    ans += 1

print(ans - 1)

# for _ in range(min_len):
#     if time == k:
#         print(ans)
#         exit()
#     if time > k:
#         print(ans - 1)
#         exit()
#     if len_a == a_i:
#         # 残りのBを数えて終わり
#         for b in b_sum_list[b_i:]:
#             time += b
#             ans += 1
#             if time > k:
#                 print(ans - 1)
#                 exit()
#         print(ans)
#         exit()

#     if len_b == b_i:
#         # 残りのAを数えて終わり
#         for a in a_sum_list[a_i:]:
#             time += a
#             ans += 1
#             if time > k:
#                 print(ans - 1)
#                 exit()
#         print(ans)
#         exit()

#     if a_sum_list[a_i] < b_sum_list[b_i]:
#         time += a_sum_list[a_i]
#         a_i += 1
#     elif a_sum_list[a_i] > b_sum_list[b_i]:
#         time += b_sum_list[b_i]
#         b_i += 1
#     else:
#         if len_a - a_i > len_b - b_i:
#             time += a_sum_list[a_i]
#             a_i += 1
#         elif len_a - a_i < len_b - b_i:
#             time += b_sum_list[b_i]
#             b_i += 1
#         else:
#             time += a_sum_list[a_i]
#             a_i += 1
#     ans += 1