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:
def main():
    N, M, K = input_ints()
    A = input_int_list_in_line()
    B = input_int_list_in_line()

    i = 0
    j = 0
    count = 0

    while K > 0:
        if i not in range(N) and j not in range(M):
            break

        if i not in range(N):
            K -= B[j]
            if K < 0:
                break
            count += 1
            j += 1
            continue

        if j not in range(M):
            K -= A[i]
            if K < 0:
                break
            count += 1
            i += 1
            continue

        if A[i] > B[j]:
            K -= B[j]
            if K < 0:
                break
            count += 1
            j += 1
            continue
        elif A[i] < B[j]:
            K -= A[i]
            if K < 0:
                break
            count += 1
            i += 1
            continue
        else:
            if N - i == 1:
                K -= B[j]
                if K < 0:
                    break
                count += 1
                j += 1
                continue
            elif M - j == 1:
                K -= A[i]
                if K < 0:
                    break
                count += 1
                i += 1
                continue
            else:
                K -= B[j]
                if K < 0:
                    break
                count += 1
                j += 1
                continue

    print(count)


def input_ints():
    line_list = input().split()

    if len(line_list) == 1:
        return int(line_list[0])
    else:
        return map(int, line_list)


def input_int_list_in_line():
    return list(map(int, input().split()))


def input_int_tuple_list(n: int):
    return [tuple(map(int, input().split())) for _ in range(n)]


main()

Submission status: Wrong Answer

Solution code:
def main():
    N, M, K = input_ints()
    A = input_int_list_in_line()
    B = input_int_list_in_line()

    i = 0
    j = 0
    count = 0

    while K > 0:
        if i not in range(N) and j not in range(M):
            break

        if i not in range(N):
            K -= B[j]
            if K < 0:
                break
            count += 1
            j += 1
            continue

        if j not in range(M):
            K -= A[i]
            if K < 0:
                break
            count += 1
            i += 1
            continue

        if A[i] > B[j]:
            K -= B[j]
            if K < 0:
                break
            count += 1
            j += 1
            continue
        else:
            K -= A[i]
            if K < 0:
                break
            count += 1
            i += 1
            continue

    print(count)




def input_ints():
    line_list = input().split()

    if len(line_list) == 1:
        return int(line_list[0])
    else:
        return map(int, line_list)


def input_int_list_in_line():
    return list(map(int, input().split()))


def input_int_tuple_list(n: int):
    return [tuple(map(int, input().split())) for _ in range(n)]


main()

Submission status: Wrong Answer

Solution code:
def main():
    N, M, K = input_ints()
    A = input_int_list_in_line()
    B = input_int_list_in_line()

    i = 0
    j = 0
    count = 0

    while K > 0:
        if i not in range(N) and j not in range(M):
            break

        if i not in range(N):
            K -= B[j]
            count += 1
            j += 1
            continue

        if j not in range(M):
            K -= A[i]
            count += 1
            i += 1
            continue

        if A[i] > B[j]:
            K -= B[j]
            if K < 0:
                break
            count += 1
            j += 1
            continue
        else:
            K -= A[i]
            if K < 0:
                break
            count += 1
            i += 1
            continue

    print(count)




def input_ints():
    line_list = input().split()

    if len(line_list) == 1:
        return int(line_list[0])
    else:
        return map(int, line_list)


def input_int_list_in_line():
    return list(map(int, input().split()))


def input_int_tuple_list(n: int):
    return [tuple(map(int, input().split())) for _ in range(n)]


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

pointerA = 0
pointerB = 0

numberOfBooks = 0

while True:
  if pointerA < len(A) and pointerB < len(B):
    if A[pointerA] <= B[pointerB]:
      K -= A[pointerA]
      pointerA += 1
    else:
      K -= B[pointerB]
      pointerB += 1
  elif pointerA < len(A):
    K -= A[pointerA]
    pointerA += 1
  elif pointerB < len(B):
    K -= B[pointerB]
    pointerB += 1

  if K == 0:
    numberOfBooks += 1
    break

  if K < 0:
    break

  numberOfBooks += 1


print(numberOfBooks)

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

pointerA = 0
pointerB = 0

numberOfBooks = 0

while True:
  if pointerA < len(A) and pointerB < len(B):
    if A[pointerA] < B[pointerB]:
      K -= A[pointerA]
      pointerA += 1
    else:
      K -= B[pointerB]
      pointerB += 1
  elif pointerA < len(A):
    K -= A[pointerA]
    pointerA += 1
  elif pointerB < len(B):
    K -= B[pointerB]
    pointerB += 1

  if K == 0:
    numberOfBooks += 1
    break

  if K < 0:
    break

  numberOfBooks += 1


print(numberOfBooks)

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
t = 0
a = b = 0
while a < len(A) or b < len(B):
    if a < len(A) and b < len(B):
        if A[a] < B[b]:
            t += A[a]
            a += 1
            if K < t:
                break
        else:
            t += B[b]
            b += 1
            if K < t:
                break
    elif a < len(A):
        t += A[a]
        a += 1
        if K < t:
            break
    else:
        t += B[b]
        b += 1
        if K < t:
            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()))

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

import bisect

Apos = bisect.bisect(A, K)

if Apos == 0:
	Bpos = bisect.bisect(B, K)
	print(Bpos)
	exit()
    
V = K-A[Apos-1]
Bpos = bisect.bisect(B, V)

final = Bpos+Apos

for i in range (1, Apos):
	V = K-A[Apos-1-i]
	Bpos = bisect.bisect(B, V)
	if Bpos+Apos-i> final:
		final = Bpos+Apos-i
	if Bpos == M:
		print (final)
		exit()

print(final)

Submission status: Wrong Answer

Solution code:
from itertools import groupby, accumulate, product, permutations, combinations
def solve():
    ans = 0
    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    A = [0]+list(accumulate(A))
    B = [0]+list(accumulate(B))
    b = M
    for a in range(N+1):
        if A[a]>K:
            break
        while A[a]+B[b]>K:
            b -= 1
        ans = max(a+b,0)
    return ans
print(solve())

Submission status: Wrong Answer

Solution code:
a_book_max,b_book_max,rem_time = map(int,input().split())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
a_count = 0
b_count = 0
a_next_time = 0
b_next_time = 0
sum = 0

#残り時間が0までループ
while(rem_time >= 0):
	#次に読む本の時間をセット(本がない場合は最大値をセット)
	if a_count <= a_book_max-1 :
		a_next_time = a_list[a_count]
	else:
		a_next_time =9999999999
	if b_count <= b_book_max-1 :
		b_next_time= b_list[b_count]
	else:
		b_next_time =9999999999

	#残り時間が足らない場合は終了
	if rem_time < a_next_time and rem_time< b_next_time:
		break
    #aの方が残数が多い場合
	if  (a_book_max - a_count) > (b_book_max - b_count) :
		rem_time = rem_time - a_next_time
		a_count = a_count + 1
		sum = sum + 1
    #bの方が多い場合
	elif (a_book_max - a_count) < (b_book_max - b_count) :
		rem_time = rem_time - b_next_time
		b_count = b_count + 1
		sum = sum + 1
	else:
		#同じ冊数の場合は短い時間で読める方を有線
		if a_next_time <= b_next_time:
			rem_time = rem_time - a_next_time
			a_count = a_count + 1
		else:
			rem_time = rem_time - b_next_time
			b_count = b_count + 1
		sum = sum+1
print(sum)

Submission status: Wrong Answer

Solution code:
a_book_max,b_book_max,rem_time = map(int,input().split())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
a_count = 0
b_count = 0
a_next_time = 0
b_next_time = 0
sum = 0

#残り時間が0までループ
while(rem_time >= 0):
	#次に読む本の時間をセット(本がない場合は最大値をセット)
	if a_count <= a_book_max-1 :
		a_next_time = a_list[a_count]
	else:
		a_next_time =999999999
	if b_count <= b_book_max-1 :
		b_next_time= b_list[b_count]
	else:
		b_next_time =999999999

	#残り時間が足らない場合は終了
	if rem_time < a_next_time and rem_time< b_next_time:
		break
    #aの方が残数が多い場合
	if  (a_book_max - a_count) > (b_book_max - b_count) :
		rem_time = rem_time - a_next_time
		a_count = a_count + 1
		sum = sum + 1
    #bの方が多い場合
	elif (a_book_max - a_count) < (b_book_max - b_count) :
		rem_time = rem_time - b_next_time
		b_count = b_count + 1
		sum = sum + 1
	else:
		#同じ冊数の場合は短い時間で読める方を有線
		if a_next_time <= b_next_time:
			rem_time = rem_time - a_next_time
			a_count = a_count + 1
		else:
			rem_time = rem_time - b_next_time
			b_count = b_count + 1
		sum = sum+1
print(sum)

Submission status: Wrong Answer

Solution code:
'''
a = a1 + a2 + a3 ・・・ai
b = b1 + b2 + b3 ・・・bj
a + b <= K なれば良い
そして、本の数の最大数を求めるから、
つまり、i + j の最大の値を求める

１，まず、考えられる解法が全検索である。
しかし、N=M=200000 の場合には間に合わない。

２，次にiについてのみ考える。
i = 0,1・・・N
そして、bj <= K-ai
であるようなjの最大値を求める。

i=0 のときのjの最大値は、 j = M, M-1 
このように降順に走査すると、最初に bj <= K-ai 左の式が成立したjを求める。
このjをbest0とする

i=1 のときに選択可能なjの最大値を求める。
この最大値はbest0以下であるため、ｊ＝best0から始めることができる
'''
N, M, K = map(int,input().split())

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

#リストだと、0から始まるため、i + jの最初を０にしている
a, b = [0], [0]
#足していった合計をリストに足している
for i in range(N):
    a.append(a[i] + A[i])
for i in range(M):
    b.append(b[i] + B[i])


ans, j = 0, M

'''
aのリストは低い数字からみて、bのリストは高い数字から見る
i=0 のときのjの最大値は、 j = M, M-1 
このように降順に走査すると、最初に bj <= K-ai 左の式が成立したjを求める。
このjをbest0とする

i=1 のときに選択可能なjの最大値を求める。
この最大値はbest0以下であるため、ｊ＝best0から始めることができる
'''
# N + 1 している理由は、0がリストの最初にあるため。
#そして、0から始まる

for i in range(N+1):
    if a[i] > K:
        break
    # print(a[i])
    while b[j] > K -a[i]:
        #降順なので−１している
        j -= 1
        print(b[j])
    #ansにi+jの最大値を返している
    ans = max(ans, i + j)
print(ans)

Submission status: Wrong Answer

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

A_i = 0
B_i = 0
sum_t = 0
cnt = 0
flg = ''
while True:
  #A/Bどちらを読むか判断する
  if A[A_i] > B[B_i]:
    if sum(list(A[A_i:A_i+1])) > sum(list(B[B_i:B_i+1])):
      flg = 'B'
    else:
      flg = 'A'
  elif A[A_i] < B[B_i]:
    if sum(list(A[A_i:A_i+1])) < sum(list(B[B_i:B_i+1])):
      flg = 'A'
    else:
      flg = 'B'
  else:
    #同じ値の時はリスト位置をバランスする
    if A_i >= B_i:
      flg = 'B'
    else:
      flg = 'A'
  
  if flg == 'A':
    tmp = A[A_i]
    if A_i < (len(A)-1):
      A_i += 1
  else:
    tmp = B[B_i]
    if B_i < (len(B)-1):
      B_i += 1
  
  #合算領域
  if sum_t + tmp <= K:
    cnt += 1
    sum_t += tmp
  else:
    break

  #終端処理
  if cnt >= (N + M):
    break

  # print('カウンタ出力', A_i, B_i)


# 結果出力
print(cnt)

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/abc172/tasks/abc172_c


def eval(A, B, K):
    C = 0

    if K == 0:
        return 0

    while (A and K >= A[0]) or (B and K >= B[0]):
        if not A or not B:
            if A:
                K -= A.pop(0)
                C += 1
            else:
                K -= B.pop(0)
                C += 1
        elif A and B:
            if A[0] < B[0]:
                K -= A.pop(0)
                C += 1
            elif A[0] > B[0]:
                K -= B.pop(0)
                C += 1
            else:
                # A[0] == B[0]
                C += 1
                K -= A.pop(0)
                B.pop(0)

    return C



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

Submission status: Wrong Answer

Solution code:
done = False
i = 0
n , m , k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
summ = 0


 
while done == False:


    if len(a) == 0:
        for z in b:
            if summ+z <= k:
                summ += z
                i += 1
            else:
                done = True
                break
    elif len(b) == 0:
        for z in a:
            if summ+z <= k:
                summ += z
                i += 1
            else:
                done = True
                break

    else:
        if a[0] < b[0]:
            if summ+a[0] <= k:
                summ += a[0]
                del a[0]
                i += 1
            else:
                done = True
        else:
            if summ+b[0] <= k:
                summ += b[0]
                del b[0]
                i += 1
            else:
                done = True

print(i)

Submission status: Wrong Answer

Solution code:
n,m,k = map(int, input().split(" "))
l1 = list(map(int, input().split(" ")))
l2 = list(map(int, input().split(" ")))
c = 0


while(True):
  if(len(l1) == 0):
    if(len(l2)!=0 and l2[0] <= k):
      c+=1
      k-=l2[0]
      l2.remove(l2[0])
    else:
      break
  elif(len(l2) == 0):
    if(l1[0] <= k):
      c+=1
      k-=l1[0]
      l1.remove(l1[0])
    else:
      break

  elif(l1[0] < l2[0]):
    if(l1[0] <= k):
      c+=1
      k-=l1[0]
      l1.remove(l1[0])
    else:
      break
  else:
    if(l2[0] <= k):
      c+=1
      k-=l2[0]
      l2.remove(l2[0])
    else:
      break
    
print(c)

Submission status: Wrong Answer

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

n, m, k = map(int, input().split())
a, b, c = list(map(int, input().split())), list(map(int, input().split())), 0
ga, gb, x = True, True, 0
while 1:
    if len(a) == 0: ga = False
    if len(b) == 0: gb = False
    if not ga and not gb: break
    if not ga: x = b.pop(0)
    if not gb: x = a.pop(0)
    if ga and gb:
        if a[0] < b[0]: x = a.pop(0)
        else: x = b.pop(0)
    if k - x < 0: break
    k -= x; c += 1
print(c)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
l=list(map(int,input().split()))
ll=list(map(int,input().split()))
lll=l+ll
lll.sort()
prefix=[]
sum=0
for i in range(len(lll)):
    sum+=lll[i]
    prefix.append(sum) 

if(min(prefix)>k):
    print(0)
elif(max(prefix)<k):
    print(len(prefix))
else:
    for i in range(len(prefix)):
        if(prefix[i]==k):
            ans=i+1
            break
        elif(prefix[i]>k):
            ans=i
            break

    print(ans)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
l=list(map(int,input().split()))
ll=list(map(int,input().split()))
lll=l+ll
lll.sort()
prefix=[]
sum=0
for i in range(len(lll)):
    sum+=lll[i]
    prefix.append(sum) 

if(min(prefix)>k):
    print(0)
else:
    for i in range(len(prefix)):
        if(prefix[i]==k):
            ans=i+1
            break
        elif(prefix[i]>k):
            ans=i
            break
    print(ans)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
A = input().split()
B = input().split()
for n in range(N):
    A[n] = int(A[n])
for m in range(M):
    B[m] = int(B[m])
Ka = 0
ca = 0
for a in range (N):
    if Ka + A[a] <= K:
        Ka += A[a]
        ca += 1
    else:
        break
Kb = 0
cb= 0
for b in range (M):
    if Kb + B[b] <= K:
        Kb += B[b]
        cb += 1
    else:
        break
cou = 0
for i in range (1, ca+1):
    c = i
    s = 0
    for a in range (i):
        s += A[a]
    for b in range(cb):
        s += B[b]
        if s > K:
            break
        c += 1
    if c > cou:
        cou = c
print(cou)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
A = input().split()
B = input().split()
for n in range(N):
    A[n] = int(A[n])
for m in range(M):
    B[m] = int(B[m])
Ka = 0
ca = 0
for a in range (N):
    if Ka + A[a] <= K:
        Ka += A[a]
        ca += 1
    else:
        break
Kb = 0
cb= 0
for b in range (M):
    if Kb + B[b] <= K:
        Kb += B[b]
        cb += 1
    else:
        break
list_c = [ca, cb]
cou = 0
for i in range (1, ca+1):
    c = i
    s = 0
    for a in range (i):
        s += A[a]
    for b in range(cb):
        s += B[b]
        if s > K:
            break
        c += 1
    if c >= cou:
        cou = c
print(cou)

Submission status: Wrong Answer

Solution code:
n,m,l=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
time=0
c=0
while(time<l):
    if(len(a)==0 ):
        time=time+b[0]
        b.pop(0)
        if(time>l):
            break
        else:
            c=c+1
    elif(len(b)==0):
        time=time+a[0]
        a.pop(0)
        if(time>l):
            break
        else:
            c=c+1
    if( len(a)>0 and len(b)>0 and b[0]>=a[0]):
        time=time+a[0]
        a.pop(0)
        if(time>l):
            break
        else:
            c=c+1
    elif(len(a)>0 and len(b)>0 and a[0]>=b[0]):
        time=time+b[0]
        b.pop(0)
        if(time>l):
            break
        else:
            c=c+1
    if(time>=l):
        break
#     print(time,a,b)
print(c)

Submission status: Wrong Answer

Solution code:
n,m,l=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
time=0
c=0
while(time<l):
    if(len(a)==0 ):
        time=time+b[0]
        b.pop(0)
        if(time>l):
            break
        else:
            c=c+1
    if(len(b)==0):
        time=time+a[0]
        a.pop(0)
        if(time>l):
            break
        else:
            c=c+1
    if( len(a)>0 and len(b)>0 and a[0]<b[0]):
        time=time+a[0]
        a.pop(0)
        if(time>l):
            break
        else:
            c=c+1
    elif(len(a)>0 and len(b)>0 and a[0]>b[0]):
        time=time+b[0]
        b.pop(0)
        if(time>l):
            break
        else:
            c=c+1
    else:
        break
    if(time>=l):
        break
#     print(time,a,b)
print(c)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
A = input().split()
B = input().split()
for i in range(len(A)):
    A[i] = int(A[i])
for i in range(len(B)):
    B[i] = int(B[i])
A.reverse()
B.reverse()
KK = 0
c= 0
while KK <= K:
    if len(A) == 0:
        KK += B[0]
        if KK <= K:
            c += 0
    if len(B) == 0:
        KK += A[0]
        if KK <= K:
            c += 0
    if len(A) == 0 and len(B) == 0:
         KK += K + 1
    if len(A) != 0 and len(B) != 0:
        if A[0] < B[0]:
            KK += A[0]
            if KK <= K:
                c += 0
            del A[0]
        else:
            KK += B[0]
            if KK <= K:
                c += 0
            del B[0]
    
print(c)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
A = input().split()
B = input().split()
for i in range(len(A)):
    A[i] = int(A[i])
for i in range(len(B)):
    B[i] = int(B[i])
A.reverse()
B.reverse()
KK = 0
c= 0
while KK <= K:
    if len(A) == 0:
        KK += B[0]
        c += 1
    if len(B) == 0:
        KK += A[0]
        c += 1
    if len(A) == 0 and len(B) == 0:
        break
    if len(A) != 0 and len(B) != 0:
        if A[0] < B[0]:
            KK += A[0]
            c += 1
            del A[0]
        else:
            KK += B[0]
            c += 1
            del B[0]
print(c)

Submission status: Wrong Answer

Solution code:
import sys

P = list(map(int,input().split()))
N,M,K = P[0],P[1],P[2]
A = list(map(int,input().split()))
B = list(map(int,input().split()))

if K < min(A) and min(B):
    print(0)
    sys.exit()

t = 0
c = 0
while(K>t):
    if (A[0]>B[0]):
        if (t+B[0]>K):
            break
        t += B[0]
        del B[0]
        c += 1
        if(B==[]):
            B.append(1000000000)
    else:
        if (t+A[0]>K):
            break
        t += A[0]
        del A[0]
        c += 1
        if(A==[]):
            A.append(1000000000)

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 = [0]*(N+1)
b = [0]*(M+1)

#累積和の計算
for i in range(1, N+1):
    a[i] = a[i-1] + A[i-1]
for j in range(1, M+1):
    b[j] = b[j-1] + B[j-1]

ans = 0
for i in range(N+1):
    left = 0
    right = M
    if K - a[i] < 0:
        continue
    while left < right:
        mid = (left + right)//2
        if b[mid] < K - a[i]:
            left = mid + 1
        elif b[mid] > K - a[i]:
            right = mid - 1
    if b[left] < K - a[i]:
        j = left
    else:
        j = left - 1
    ans = max(ans, i + j)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

P = list(map(int,input().split()))
N,M,K = P[0],P[1],P[2]
A = list(map(int,input().split()))
B = list(map(int,input().split()))
Books = A + B
Books.sort()

#print(Books)

if K < min(Books):
    print(0)
    sys.exit()

t = 0
c = 0
for p in range(0,len(Books)):
    if (t + Books[p]) <= K:
        t += Books[p]
        c += 1
    else:
        break

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 = [0]*(N+1)
b = [0]*(M+1)

#累積和の計算
for i in range(1, N+1):
    a[i] = a[i-1] + A[i-1]
for j in range(1, M+1):
    b[j] = b[j-1] + B[j-1]

ans = 0
for i in range(N+1):
    left = 0
    right = M
    while left < right:
        mid = (left + right)//2
        if b[mid] < K - a[i]:
            left = mid + 1
        elif b[mid] > K - a[i]:
            right = mid - 1
    if b[left] <= K - a[i]:
        j = left
    else:
        j = left - 1
    ans = max(ans, i + j)
print(ans)

Submission status: Wrong Answer

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

count = 0
while alist[n-1] <= k or blist[m-1] <= k:
    if n > 0 and m > 0:
        if alist[n-1] <= blist[m-1]:
            k -= alist[n-1]
            n -= 1
            count += 1
        elif blist[m-1] <= alist[n-1]:
            k -= blist[m-1]
            m -= 1
            count += 1
    elif n > 0:
        k -= alist[n-1]
        n -= 1
        count += 1
    elif m > 0:
        k -= blist[m-1]
        m -= 1
        count += 1
    else:
        break

print(count)

Submission status: Wrong Answer

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

count = 0
while alist[n-1] <= k or blist[m-1] <= k:
    if n > 0 and m > 0:
        if alist[n-1] <= blist[m-1]:
            k -= alist[n-1]
            n -= 1
            count += 1
        elif blist[m-1] <= alist[n-1]:
            k -= blist[m-1]
            m -= 1
            count += 1
    elif n > 0:
        k -= alist[n-1]
        n -= 1
        count += 1
    else:
        k -= blist[m-1]
        m -= 1
        count += 1

print(count)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
a = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))

N = a[0]
M = a[1]
K = a[2]

count = 0 #読んだ冊数を記録
count_time = 0 #読んだ時間を記録
min_time = min(min(A), min(B))
num = int(K/min_time)

if K<A[0] and K<B[0]:
    print(count)
 
else:
    for i in range(num):
        if len(A)!=0 and len(B)!=0:
            if A[0] >= B[0]:
                count_time += B[0]
                count += 1
                B.pop(0)              
                continue

            elif A[0] < B[0]:
                count += 1
                count_time += A[0]
                A.pop(0)
                continue

        elif len(A)==0 and len(B)!=0:
            count += 1
            count_time += B[0]
            B.pop(0)
            continue

        elif len(B)==0 and len(A)!=0:
            count += 1
            count_time += A[0]
            A.pop(0)
            continue

        else:
            count += 1
            break
        
    print(count-1)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
a = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))

N = a[0]
M = a[1]
K = a[2]

count = 0 #読んだ冊数を記録
count_time = 0 #読んだ時間を記録

if K<A[0] and K<B[0]:
    print(count)
 
else:
    while K >= count_time:
        if len(A)!=0 and len(B)!=0:
            if A[0] >= B[0]:
                count_time += B[0]
                count += 1
                B.pop(0)              
                continue

            elif A[0] < B[0]:
                count += 1
                count_time += A[0]
                A.pop(0)
                continue

        elif len(A)==0 and len(B)!=0:
            count += 1
            count_time += B[0]
            B.pop(0)
            continue

        elif len(B)==0 and len(A)!=0:
            count += 1
            count_time += A[0]
            A.pop(0)
            continue

        else:
            count += 1
            break
        
    print(count-1)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
a = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))

N = a[0]
M = a[1]
K = a[2]

count = 0 #読んだ冊数を記録
count_time = 0 #読んだ時間を記録

if K<A[0] and K<B[0]:
    print(count)
 
else:
    while K >= count_time:
        if len(A)!=0 and len(B)!=0:
            if A[0] >= B[0]:
                count_time += B[0]
                count += 1
                B.pop(0)
                
                continue

            elif A[0] < B[0]:
                count += 1
                count_time += A[0]
                A.pop(0)
                
                continue

        elif len(A)==0 and len(B)!=0:
            count += 1
            count_time += B[0]
            B.pop(0)
            
            continue

        elif len(B)==0 and len(A)!=0:
            count += 1
            count_time += A[0]
            A.pop(0)
            
            continue

        else:
            count += 1
            
            break
        
    print(count-1)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
a = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))

N = a[0]
M = a[1]
K = a[2]

count = 0 #読んだ冊数を記録
count_time = 0 #読んだ時間を記録

if K<A[0] and K<B[0]:
    print(count)
 
else:
    while K >= count_time:
        if len(A)!=0 and len(B)!=0:
            if A[0] >= B[0]:
                count_time += B[0]
                count += 1
                B.pop(0)
                print(count_time)
                continue

            elif A[0] < B[0]:
                count += 1
                count_time += A[0]
                A.pop(0)
                print(count_time)
                continue

        elif len(A)==0 and len(B)!=0:
            count += 1
            count_time += B[0]
            B.pop(0)
            print(count_time)
            continue

        elif len(B)==0 and len(A)!=0:
            count += 1
            count_time += A[0]
            A.pop(0)
            print(count_time)
            continue

        else:
            count += 1
            print(count_time)
            break
        
    print(count-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_i = 0
B_i = 0
sum_t = 0
cnt = 0
while True:
  #A/Bどちらを読むか判断する
  if sum(list(A[A_i:A_i+1])) > sum(list(A[A_i:A_i+1])):
    tmp = B[B_i]
    if B_i < (len(B)-1):
      B_i += 1
  else:
    tmp = A[A_i]
    if A_i < (len(A)-1):
      A_i += 1
  
  #合算領域
  if sum_t + tmp <= K:
    cnt += 1
    sum_t += tmp
  else:
    break

  #終端処理
  if cnt >= (N + M):
    break

  #print('カウンタ出力', A_i, B_i)


# 結果出力
print(cnt)

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 = 0
B_i = 0
sum = 0
cnt = 0
while True:
  #リストAとBの比較領域
  if A[A_i] > B[B_i]:
    tmp = B[B_i]
    if B_i < (len(B)-1):
      B_i += 1
  else:
    tmp = A[A_i]
    if A_i < (len(A)-1):
      A_i += 1
  
  #合算領域
  if sum + tmp <= K:
    cnt += 1
    sum += tmp
  else:
    break

  #終端処理
  #if A_i == (len(A)-1) and B_i == (len(B)-1):
  #  break

  #print('カウンタ出力', A_i, B_i)


# 結果出力
print(cnt)

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 = 0
B_i = 0
sum = 0
cnt = 0
while True:
  #リストAとBの比較領域
  if A[A_i] > B[B_i]:
    tmp = B[B_i]
    if B_i < (len(B)-1):
      B_i += 1
  else:
    tmp = A[A_i]
    if A_i < (len(A)-1):
      A_i += 1
  
  #合算領域
  if sum + tmp <= K:
    cnt += 1
    sum += tmp
  else:
    break

  #終端処理
  if A_i == (len(A)-1) and B_i == (len(B)-1):
    break

# 結果出力
print(cnt)

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 ** 10

sum = 0
cnt = 0
while True:
  if A[0] <= B[0]:
    sum += A.pop(0)
    if len(A) == 0:
      A.append(MAX)
  else:
    sum += B.pop(0)
    if len(B) == 0:
      B.append(MAX)

  if sum > K:
    break
  else:
    cnt += 1

  if A[0] == MAX and B[0] == MAX:
    break

print(cnt)