Problem:


Score : 300 points

Problem Statement

We have two desks: A and B. Desk A has a vertical stack of N books on it, and Desk B similarly has M books on it.

It takes us A_i minutes to read the i-th book from the top on Desk A (1 \leq i \leq N), and B_i minutes to read the i-th book from the top on Desk B (1 \leq i \leq M).

Consider the following action:

Choose a desk with a book remaining, read the topmost book on that desk, and remove it from the desk.

How many books can we read at most by repeating this action so that it takes us at most K minutes in total? We ignore the time it takes to do anything other than reading.

Constraints

1 \leq N, M \leq 200000

1 \leq K \leq 10^9

1 \leq A_i, B_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M K
A_1 A_2 \ldots A_N
B_1 B_2 \ldots B_M

Output

Print an integer representing the maximum number of books that can be read.

Sample Input 1

3 4 240
60 90 120
80 150 80 150

Sample Output 1

3

In this case, it takes us 60, 90, 120 minutes to read the 1-st, 2-nd, 3-rd books from the top on Desk A, and 80, 150, 80, 150 minutes to read the 1-st, 2-nd, 3-rd, 4-th books from the top on Desk B, respectively.

We can read three books in 230 minutes, as shown below, and this is the maximum number of books we can read within 240 minutes.

Read the topmost book on Desk A in 60 minutes, and remove that book from the desk.

Read the topmost book on Desk B in 80 minutes, and remove that book from the desk.

Read the topmost book on Desk A in 90 minutes, and remove that book from the desk.

Sample Input 2

3 4 730
60 90 120
80 150 80 150

Sample Output 2

7

Sample Input 3

5 4 1
1000000000 1000000000 1000000000 1000000000 1000000000
1000000000 1000000000 1000000000 1000000000

Sample Output 3

0

Watch out for integer overflows.



Sample input:
3 4 240
60 90 120
80 150 80 150


Sample output:
3

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
alis = list(map(int, input().split())) + [100000000000]
blis = list(map(int, input().split())) + [100000000000]
su = 0
a = 0
b = 0
if sum(alis) + sum(blis) - 200000000000 < k:
  print(len(alis) + len(blis))
  quit()
  
while su <= k:
  if alis[a] > blis[b]:
    su += blis[b]
    b += 1
  else:
    su += alis[a]
    a += 1
    
print(a + b - 1)

Submission status: Wrong Answer

Solution code:
from collections import deque
N, M, K = map(int, input().split())
*A, = map(int, input().split())
*B, = map(int, input().split())
a = deque(A)
b = deque(B)
ans = 0
l = len(a) + len(b)
while a and b:
    if K - a[0] >= 0 or K - b[0] >= 0:
        if a[0] > b[0]:
            x = b.popleft()
            K = K - x
            ans += 1
        elif a[0] < b[0]:
            x = a.popleft()
            K = K - x
            ans += 1
        elif a[0] == b[0] and len(a) >= 2 and len(b) >= 2:
            if a[1] > b[1]:
                x = b.popleft()
            else:
                x = a.popleft()
            K = K - x
            ans += 1
        elif a[0] == b[0] and len(a) == 1:
            x = a.popleft()
            K = K - x
            ans += 1
        elif a[0] == b[0] and len(b) == 1:
            x = b.popleft()
            K = K - x
            ans += 1
    else:
        break
C = list(a) + list(b)
c = deque(C)
while c:
    if K - c[0] >= 0:
        x = c.popleft()
        K = K - x
        ans += 1
    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()))

sum_time = 0
count = 0
a, b = 0, 0
while sum_time < K:
    if (len(A) - 1 < a and len(B) - 1 < b):
        print(count)
        exit()
    if (len(A) - 1 < a and len(B) - 1 >= b):
        count += 1
        sum_time += B[b]
        b += 1
        continue
    elif (len(A) - 1 >= a and len(B) - 1 < b):
        count += 1
        sum_time += A[a]
        a += 1
        continue

    if (A[a] <= B[b]):
        count += 1
        sum_time += A[a]
        a += 1
    else:
        count += 1
        sum_time += B[b]
        b += 1

if (sum_time == K):
    print(count)
    exit()
elif(sum_time > K):
    print(count - 1)
    exit()

Submission status: Wrong Answer

Solution code:
#関数リスト
import sys
import numpy
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

n, k , m = MI()
a = numpy.cumsum(LI())
b = numpy.cumsum(LI())
a = a[a<=m]
b = b[b<=m]

result = -1
if len(a) >= 0:
    for i in range(len(a)):
        tempa = a[i]
        tempb = len(b[b<=m-tempa])
        if result < i+tempb:
            result = i+tempb
    print(result+1)
else:
    print(len(b[b<=m]))

Submission status: Wrong Answer

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

i, j, ans = 0, 0, 0
while K > 0:
    if i == N and j == M:
        break
    elif A[i] < B[j]:
        K -= A[i]
        i += 1
    else:
        K -= B[j]
        j += 1
    ans += 1

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

A_ruiseki = [A[0]]
for i in range(1, n):
    if A_ruiseki[i-1]+A[i] <= k :
        A_ruiseki.append(A_ruiseki[i-1]+A[i])
    else:
        break

ans = 0

for i in range(len(A_ruiseki)):
    time = A_ruiseki[i]
    if time > k:
        continue
    cnt_b = 0
    while cnt_b < m:
        if time + B[cnt_b] <= k:
            time += B[cnt_b]
            cnt_b += 1
        else:
            break

    ans = max(ans, (i+1) + cnt_b)

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()))
amin=[0]*(n+1)
bmin=[0]*(m+1)
for i in range(n):
    amin[i+1]=amin[i]+a[i]
for i in range(m):
    bmin[i+1]=bmin[i]+b[i]
at=[i for i in amin if i<=k]
bt=[i for i in bmin if i<=k]
at.reverse()
bt.reverse()
atl=len(at)
btl=len(bt)
answer=0
for i in range(atl-1):
    for j in range(btl-1):
        if at[i]+bt[j]<=k:
            answer=max(answer,atl-i-1+btl-j-1)
print(answer)

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(" ")))
total,count = 0,0
for i in range(max(n,m)):
	if i < n:
		if total+a[i] > k:
			break
		else:
			total += a[i]
			count +=1
	if i < m:
		if total+b[i] > k:
			break
		else:
			total += b[i]
			count += 1
print(count)

Submission status: Wrong Answer

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

a, b = 0, 0

while k > 0:
  if a < n and b < m:
    if As[a] <= Bs[b]:
      if k < As[a]:break
      k -= As[a]
      a += 1
    else:
      if k < Bs[b]:break
      k -= Bs[b]
      b += 1
  elif a < n:
    if k < As[a]:break
    k -= As[a]
    a += 1
  elif b < m:
    if k < Bs[b]:break
    k -= Bs[b]
    b += 1
  else:
    break

print(a+b)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# 標準入力を取得
N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))

# 求解処理
ans = 0
n, m, k = 0, 0, 0
while True:
    if n >= N and m >= M:
        break
    if n >= N:
        k += B[m]
        if k > K:
            break
        ans += 1
        m += 1
        continue
    if m >= M:
        k += A[n]
        if k > K:
            break
        ans += 1
        n += 1
        continue
    A_n, B_m = A[n], B[m]
    if A_n < B_m:
        k += A_n
        n += 1
    elif A_n > B_m:
        k += B_m
        m += 1
    else:
        if n == N - 1:
            k += B_m
            m += 1
        elif m == M - 1:
            k += A_n
            n += 1
        else:
            A_nn, B_mm = A[n+1], B[m+1]
            if A_nn <= B_mm:
                k += A_n
                n += 1
            else:
                k += B_m
                m += 1
    if k > K:
        break
    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()))

sa=[]
ka=0
sb=[]
kb=0
for i in range(n):
  if ka+a[i]<=k:
    ka+=a[i]
    sa.append(a[i])
  else:
    break
for i in range(m):
  if kb+b[i]<=k:
    kb+=b[i]
    sb.append(b[i])
  else:
    break
ans=max(len(sa),len(sb))
tb=[]
for i in range(len(sa)):
  if sa[i]>k:
    break
  while kb+sa[i]>k:
    kb-=sb[-1]
    sb.pop(-1)
  tb.append(sa[i])
  kb+=sa[i]
  if ans<(len(sb)+len(tb)):
    ans=len(sb)
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()))

ans = 0
time = 0
while True:
    book = None
    # AにもBにも本がない
    if len(A) == 0 and len(B) == 0:
        break
    # AにもBにも本がある
    if len(A) > 0 and len(B) > 0:
        for i in range(max(len(A), len(B))):
            if i >= len(A):
                ai = len(A) - 1
            else:
                ai = i

            if i >= len(B):
                bi = len(B) - 1
            else:
                bi = i

            if A[ai] == B[bi]:
                if time + A[ai] > K:
                    book = A.pop(0)
                    break
                else:
                    continue
            elif A[ai] > B[bi]:
                book = B.pop(0)
                break
            elif A[ai] < B[bi]:
                book = A.pop(0)
                break
    elif len(B) == 0 and len(A) > 0:
        book = A.pop(0)
    elif len(A) == 0 and len(B) > 0:
        book = B.pop(0)

    if book is None:
        break
    if time + book <= K:
        time += book
        ans += 1
    else:
        break

print(ans)

Submission status: Wrong Answer

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

import sys
# import math
# import numpy as np
# import scipy.sparse.csgraph as cs            # csgraph_from_dense(ndarray, null_value=inf), bellman_ford(G, return_predecessors=True), dijkstra, floyd_warshall
# import random                                # random, uniform, randint, randrange, shuffle, sample
# import string                                # ascii_lowercase, ascii_uppercase, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from datetime import date, datetime          # date.today(), date(year,month,day) => date obj; datetime.now(), datetime(year,month,day,hour,second,microsecond) => datetime obj; subtraction => timedelta obj
# from datetime.datetime import strptime       # strptime('2019/01/01 10:05:20', '%Y/%m/%d/ %H:%M:%S') returns datetime obj
# from datetime import timedelta               # td.days, td.seconds, td.microseconds, td.total_seconds(). abs function is also available.
# from copy import copy, deepcopy              # use deepcopy to copy multi-dimentional matrix without reference
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from fractions import Fraction               # Fraction(a, b) => a / b ∈ Q. note: Fraction(0.1) do not returns Fraciton(1, 10). Fraction('0.1') returns Fraction(1, 10)



def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79e+308
    # inf = 2 ** 63 - 1             # (for fast JIT compile in PyPy) 9.22e+18
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def isp():   return input().split()
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    def simulation(k):
        cnt = 0
        while True:
            assert k >= 0
            if A and B:
                # print(k)
                if min(A[-1], B[-1]) > k:
                    break
                if A[-1] < B[-1]:
                    k -= A.pop()
                else:
                    k -= B.pop()
                cnt += 1
            elif A:
                if A[-1] > k:
                    break
                k -= A.pop()
                cnt += 1
            elif B:
                if B[-1] > k:
                    break
                k -= B.pop()
                cnt += 1
            else:
                break
        return cnt 

    
    n, m, k = mi()
    A = lmi()
    B = lmi()
    A.reverse()
    B.reverse()

    print(simulation(k))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
a = [input() for l in range(0,3)]
a1 = [int(p) for p in a[0].split()]
a2 = [int(p) for p in a[1].split()]
a3 = [int(p) for p in a[2].split()]
a4 = a2 + a3
b = sorted(a4)
c = 0
for i in range(0,len(b)):
    c = c + b[i]
if c <= a1[2]:
    print(len(b))
else:
    s = 0
    t = 0
    while s <= a1[2] and t < len(b):
        s = s + b[t]
        t = t + 1
    print(t-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()))
X = sorted(A + B)
cnt = 0
for i in range(len(X)):
    if K - X[i] < 0:
        break
    else:
        K -= X[i]
        cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
import bisect

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
cuma, cumb = [a[0]], [b[0]]
for i in range(1, n):
    cuma.append(cuma[i-1] + a[i])
for i in range(1, m):
    cumb.append(cumb[i-1] + b[i])
ans = [0]
for i in range(n):
    if cuma[i] <= k:
        t = k - cuma[i]
        if t >= cumb[-1]:
            j = m
        else:
            j = bisect.bisect_left(cumb, t)
        ans.append(i+j+1)
print(max(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()))

cnt = 0
A_i = 0
B_i = 0
while K > 0:
    if A_i >= len(A):
        if K >= B[B_i]:
            K = K - B[B_i]
            B_i += 1
            cnt += 1
        else:
            break
    elif B_i >= len(B):
        if K >= A[A_i]:
            K = K - A[A_i]
            A_i += 1
            cnt += 1
        else:
            break
    elif A[A_i] < B[B_i]:
        if K >= A[A_i]:
            K = K - A[A_i]
            A_i += 1
            cnt += 1
        else:
            break
    else:
        if K >= B[B_i]:
            K = K - B[B_i]
            B_i += 1
            cnt += 1
        else:
            break

print(cnt)

Submission status: Wrong Answer

Solution code:
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline

    n,m,k=map(int, readline().rstrip().split())
    aa=list(map(int, readline().rstrip().split()))
    bb=list(map(int, readline().rstrip().split()))
    dp=0
    asum=[0]*n
    bsum=[0]*m
    memo=[0]*n
    asum[0]=aa[0]
    bsum[0]=bb[0]
    memo[0]=k-aa[0]
    mp=n-1
    ans=0
    for i in range(1,n):
        asum[i]=(aa[i]+aa[i-1])
        memo[0]=k-asum[i]
    for i in range(1,m):
        bsum[i]=(bb[i]+bb[i-1])
    for i in range(m+1):
        if i==0:
            x=0
        else:
            x = bsum[i-1]

        while mp>=0:
            if asum[mp]+x <= k:
                break
            else:
                mp-=1
            if mp==-1:
                break
        if asum[mp]+x <= k:
            ans = max(i + mp+1,ans)

    print(ans)

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------

Submission status: Wrong Answer

Solution code:
import numpy as np

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

a = input().split()
np_a=np.array(a, dtype='int64')
b = input().split()
np_b=np.array(b, dtype='int64')

ia=0
ib=0
time=0
hon=n+m
for i in range(0,n+m):
  if (ia == n): 
    time+=np_b[ib]
    ib+=1
  elif (ib == m): 
    time+=np_a[ia] 
    ia+=1
  elif (ia < n or ib < m): 
    if (np_a[ia] <= np_b[ib]):
      time+=np_a[ia]
      ia+=1
    else:
      time+=np_b[ib]
      ib=+1

  if (time > k): 
    hon=i
    break

print (hon)

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)

time = 0
ans = 0

i, j = 0, 0
if A[0]>K and B[0]>K:
    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:
#!/usr/bin/env python3
import sys


def solve(N: int, M: int, K: int, A: "List[int]", B: "List[int]"):
    candidateA = []
    weightA = 0
    tmp_A = N
    for idx, a in enumerate(A):
        if weightA + a > K:
            tmp_A = idx
            break
        else:
            weightA += a
    candidateA = A[:tmp_A]
    max_count = current_count = len(candidateA)

    candidateB = []
    weightB = 0
    terminated=False
    for b in B:
        if terminated == True and weightA + weightB > K:
            break

        if len(candidateA)==0:
            break

        if weightA + weightB + b <= K:
            weightB += b
            candidateB.append(b)
            current_count += 1

        elif terminated==False:
            while weightA + weightB + b > K:
                if len(candidateA)>0:
                    weightA -= candidateA.pop()
                    current_count -= 1
                else:
                    terminated=True

            if weightA + weightB + b <= K:
                weightB += b
                candidateB.append(b)
                current_count += 1
        max_count = max(max_count, current_count)

    print(max_count)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    B = [int(next(tokens)) for _ in range(M)]  # type: "List[int]"
    solve(N, M, K, A, B)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
import copy
import bisect
def main():
    N, M, K = map(int, input().split())
    MAX = 10 ** 9 + 7
    a = [int(i) for i in input().split()]
    b = [int(i) for i in input().split()]
    A = []
    B = []
    A.append(0)
    B.append(0)
    for i in range(N):
        A.append(a[i] + A[i])
    for i in range(M):
        B.append(b[i] + B[i])
    B.append(B[M - 1] + MAX)
    ans = 0
    for i in range(N+1):
        if A[i] <= K:
            a = bisect.bisect_right(B, (K - A[i]))
            if B[a] + K - A[i] > K:
                a -= 1
            ans = max(ans, (i + a))
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import deque

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

A_que=deque(A)
B_que=deque(B)

ans = 0
for i in range(N+M):
    if A_que and B_que:
        if A_que[0] > B_que[0]:
            K -= B_que.popleft()
        else:
            K -= A_que.popleft()
    elif A_que:
        K -= A_que.popleft()
    elif B_que:
        K -= B_que.popleft()
    else:
        break
    if K >= 0:
        ans += 1
    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()))

mmax = 0
pre = False
num = 0
ans = 0
ans2 = 0
for i in range(N+1):
  if i == 0:
    ans = 0
  else:
    ans += A[i-1]
  if ans > K:
    break
  for j in range(M+1):
    if j == 0:
      ans2 = ans
    else:
      ans2 += B[j-1]
    if ans2 > K:
      break
    else:
      mmax = max(mmax, i+j)
    print(i, j, ans2, mmax)

print(mmax)

Submission status: Wrong Answer

Solution code:
from collections import deque
n, m, k = map(int, input().split())
A = deque(map(int, input().split()))
B = deque(map(int, input().split()))

cnt = 0
while k >= 0:
    if not A:
        a = 10 ** 9
    else:
        a = A.popleft()
    if not B:
        b = 10 ** 9
    else:
        b = B.popleft()
    if a <= b:
        k -= a
        B.appendleft(b)
        cnt += 1
    else:
        k -= b
        A.appendleft(a)
        cnt += 1
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()))
max_c = 0
t = 0
cnt = 0
flag = 0

for i in range(n):
  if sum(a[:i]) > k:
    break
  for j in range(m):
    t = sum(a[:i]) + sum(b[:j])
    if t > k:
      break
    else :
      if i+j > max_c:
        max_c = i+j
print(max_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()))

count = 0
while K > 0:
    if A != [] and B != []:
        if A[0] > B[0]:
            K -= B.pop(0)
        else:
            K -= A.pop(0)
    elif A == []:
        K -= B.pop(0)
    else:
        K -= A.pop(0)
    if K > 0:
        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()))
if sum(A)+sum(B)<=K:
    print(len(A)+len(B))
else:
    ans=0
    count=0
    while count<K and len(A)!=0 and len(B)!=0:
        m=min(A[0],B[0])
        count+=m
        if m==A[0]:
            A.pop(0)
        else:
            B.pop(0)
        ans+=1
    if count<K and len(A)==0:
        while count<K:
            m=B[0]
            count+=m
            B.pop(0)
            ans+=1
    if count<K and len(B)==0:
        while count<K:
            m=A[0]
            count+=m
            A.pop(0)
            ans+=1
    if count>K:
        ans-=1
    print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

n, m, k = [int(e) for e in input().split()]
a = np.array([int(e) for e in input().split()])
b = np.array([int(e) for e in input().split()])

asum = a.cumsum()
bsum = b.cumsum()

#aのみbのみ
onlya = (asum < k).sum()
onlyb = (bsum < k).sum()
ans = max(onlya,onlyb)

for i,t in enumerate(asum):
    for j,s in enumerate(bsum):
        if t+s <= k and i+j+2 > ans:
            ans = i+j+2

print(ans)

Submission status: Wrong Answer

Solution code:
'''
.append(要素) リストに要素を追加
.extend(リスト) リストを連結する
.insert(場所,要素) 指定した場所に要素追加
del 配列名[場所]
-1で末尾で末尾から一つ前

sort()
sorted(reverse=true)

配列の初期化
配列名=[a]*n+[b]*m

Decimal()
'''

from sys import stdin
from itertools import accumulate, dropwhile, takewhile, groupby
import bisect
import copy
import math
from functools import reduce
from operator import mul
from collections import Counter
import itertools
import fractions
import sys

d1 = stdin.readline().rstrip().split()
N = int(d1[0])
M = int(d1[1])
K = int(d1[2])
A = [int(s) for s in stdin.readline().rstrip().split()]
B = [int(s) for s in stdin.readline().rstrip().split()]

count = 0
minute = 0
posA = 0
posB = 0
while(True):
    if A[-1] == 0 and B[-1] == 0:
        break
    if A[-1] != 0 and (B[-1] == 0 or A[posA] <= B[posB]):
        minute += A[posA]
        A[posA] = 0
        posA += 1
        if minute > K:
            break
        count += 1
        continue
    if B[-1] != 0 and(A[-1] == 0 or A[posA] > B[posB]):
        minute += B[posB]
        B[posB] = 0
        posB += 1
        if minute > K:
            break
        count += 1
        continue
print(count)

Submission status: Wrong Answer

Solution code:
import sys
data = sys.stdin

conversion_data = []
for l in data:
    conversion_data.append([int(i) for i in l.split()])

table_a = conversion_data[1]
table_b = conversion_data[2]

N = conversion_data[0][0]
M = conversion_data[0][1]
limit = conversion_data[0][2]
max = max([N, M])

total_time = 0
position_a = 0
position_b = 0

for i in range(max):
  if position_a < N:
      a = table_a[position_a]
      if (a + total_time) <= limit:
          total_time += a
          position_a += 1
  
  if position_b < M:
    b = table_b[position_b]
    if (b + total_time) <= limit:
      total_time += b
      position_b += 1
  
print(position_a + position_b)

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
Ain = 0
Bin = 0
check = False
if(min(min(A),min(B))>K):
    print(0)
    exit()
while K>0:
    if(Ain != N and Bin !=M): 
        if(A[Ain] < B[Bin]):
            K-=A[Ain]
            Ain += 1
        elif(A[Ain]>B[Bin]):
            K-=B[Bin]
            Bin += 1
        
    elif((Ain == N) and (Bin == M)):
        check = True
        break
    elif(Ain==N):
        K -= B[Bin]
        Bin += 1
    elif(Bin==M):
        K -= A[Ain]
        Ain += 1
if((K==0) or check):
    print(Ain+Bin)
else:
    print((Ain+Bin)-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()))

count = 0
while K >= 0:
    if not A and not B:
        count += 1
        break
    # Aが存在してる
    if A:
        # Bが存在してる
        if B:
            if A[0] >= B[0]:
                K -= B[0]
                B.pop(0)
                count += 1
                continue
        K -= A[0]
        A.pop(0)
        count += 1
        continue

    if B:
        if A:
            if B[0] >= A[0]:
                K -= A[0]
                A.pop(0)
                count += 1
                continue
        K -= B[0]
        B.pop(0)
        count += 1
        continue
if count <= 0:
    print(0)
    exit()
print(count - 1)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().rstrip().split())
As = [int(x) for x in input().rstrip().split()]
Bs = [int(x) for x in input().rstrip().split()]
ln_max = len(As)
lm_max = len(Bs)
ln = 0
lm = 0
count_time = 0
count_book = 0
while True:
    if count_time >= K:
        break
    if ln >= ln_max and lm >= lm_max:
        break
    if ln >= ln_max and lm < lm_max:
        count_time += Bs[lm]
        lm += 1
    elif lm >= lm_max and ln < ln_max:
        count_time += As[ln]
        ln += 1
    elif As[ln] > Bs[lm]:
        if count_time + Bs[lm] >= K:
            break
        count_time += Bs[lm]
        lm += 1
    else:
        if count_time + As[ln] >= K:
            break
        count_time += As[ln]
        ln += 1
    # print(f'ln: {ln}')
    # print(f'lm: {lm}')
    count_book += 1
    # print(count_time)
# print('----')
# print(N-1, M-1)
print(count_book)

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()))
C=A+B
d=0
C.sort()
if sum(C)<=K :
    print(len(C))
    sys.exit()
for i in range(len(C)) :
    d=d+C[i]
    if d>K :
        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(" ")))

a = 0
b = 0
time = 0

def search(a, b, time):
    check = False
    
    if a > len(A) - 1:
        if b > len(B) - 1:
            check = True
        else:
            time += B[b]
            b += 1
    else:
        if b > len(B) - 1:
            if a > len(A) - 1:
                check = True
            else:
                time += A[a]
                a += 1
        else:
            if A[a] >= B[b]:
                time += B[b]
                b += 1
            else:
                time += A[a]
                a += 1
    
    return a, b, time, check

for n in range(200000 * 200000):
    a, b, time, check = search(a, b, time)
    
    if check:
        print(a + b)
        break

    if time >= K:
        print(a + b - 1)
        break

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

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

A.append(K)
B.append(K)

t = 0
idx_a = 0
idx_b = 0
c = 0

while True:
    if A[idx_a] < B[idx_b]:
        temp = A[idx_a]
        idx_a += 1
    else:
        temp = B[idx_b]
        idx_b += 1

    t += temp

    if t > K:
        t -= temp
        break
    c += 1
print(c)