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())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ac = 0
bc = 0
time = 0
for i in range(n+m):
    if ac < n:
        if bc < m:
            if a[ac] < b[bc]:
                time += a[ac]
                if time > k:
                    break
                ac += 1
            else:
                time += b[bc]
                if time > k:
                    break
                bc += 1
        else:
            time += a[ac]
            if time > k:
                break
            ac += 1
    else:
        time += b[bc]
        if time > k:
            break
        bc += 1
print(ac+bc)

Submission status: Wrong Answer

Solution code:
# aとbのリストの最初を比較して、小さい方を選択して削除

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

minutes = 0
numbers = 0

while minutes <= k:

    # リストが空になるので対応
    if len(a) >= 1 and len(b) >= 1:
        read_book = min(a[0], b[0])
    elif len(a) == 0 and len(b) >= 1:
        read_book = b[0]
    elif len(a) >= 1 and len(b) == 0:
        read_book = a[0]
    else:
        break

    minutes += read_book

    # 時間が超えてたら終了、本の冊数に入れない
    if minutes > k:
        break

    numbers += 1

    if read_book in a:
        a.pop(0)
    else:
        b.pop(0)

print(numbers)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from sys import stdin

# import numpy as np
from itertools import accumulate
from bisect import bisect_right

# import sys
# sys.setrecursionlimit(10**4)


def _li():
    return list(map(int, stdin.readline().split()))


def _li_():
    return list(map(lambda x: int(x) - 1, stdin.readline().split()))


def _lf():
    return list(map(float, stdin.readline().split()))


def _ls():
    return stdin.readline().split()


def _i():
    return int(stdin.readline())


def _f():
    return float(stdin.readline())


def _s():
    return stdin.readline()[:-1]


def search(cum1, cum2, iter_max, limit):
    ans = 0
    for i in range(iter_max):
        if cum1[i] > limit:
            break
        cand = bisect_right(cum2, limit - cum1[i])
        ans = max(i + 1 + cand, ans)
    return ans


N, M, K = _li()
A_list = _li()
B_list = _li()

cum_a = list(accumulate(A_list))
cum_b = list(accumulate(B_list))

if cum_a[0] < cum_b[0]:
    print(search(cum_a, cum_b, N, K))
else:
    print(search(cum_b, cum_a, M, 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()))
ac = 0
bc = 0
time = 0
while True:
    if ac < n:
        if bc < m:
            if a[ac] < b[bc]:
                time += a[ac]
                if time > k:
                    break
                ac += 1
            else:
                time += b[bc]
                if time > k:
                    break
                bc += 1
        else:
            time += a[ac]
            if time > k:
                break
            ac += 1
    elif bc < m:
        time += b[bc]
        if time > k:
            break
        bc += 1
    else:
        break
print(ac+bc)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from sys import stdin

# import numpy as np
from itertools import accumulate
from bisect import bisect_right

# import sys
# sys.setrecursionlimit(10**4)


def _li():
    return list(map(int, stdin.readline().split()))


def _li_():
    return list(map(lambda x: int(x) - 1, stdin.readline().split()))


def _lf():
    return list(map(float, stdin.readline().split()))


def _ls():
    return stdin.readline().split()


def _i():
    return int(stdin.readline())


def _f():
    return float(stdin.readline())


def _s():
    return stdin.readline()[:-1]


N, M, K = _li()
A_list = _li()
B_list = _li()

cum_a = list(accumulate(A_list))
cum_b = list(accumulate(B_list))

ans = 0
for i in range(N):
    if cum_a[i] > K:
        break
    cand = bisect_right(cum_b, K - cum_a[i])
    ans = max(i + 1 + cand, 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()))
ac = 0
bc = 0
time = 0
for i in range(4000000):
    if ac < n:
        if bc < m:
            if a[ac] < b[bc]:
                time += a[ac]
                if time > k:
                    break
                ac += 1
            else:
                time += b[bc]
                if time > k:
                    break
                bc += 1
        else:
            time += a[ac]
            if time > k:
                break
            ac += 1
    elif bc < m:
        time += b[bc]
        if time > k:
            break
        bc += 1
    else:
        break
print(ac+bc)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from sys import stdin
import numpy as np

# import sys
# sys.setrecursionlimit(10**4)


def _li():
    return list(map(int, stdin.readline().split()))


def _li_():
    return list(map(lambda x: int(x) - 1, stdin.readline().split()))


def _lf():
    return list(map(float, stdin.readline().split()))


def _ls():
    return stdin.readline().split()


def _i():
    return int(stdin.readline())


def _f():
    return float(stdin.readline())


def _s():
    return stdin.readline()[:-1]


N, M, K = _li()
A_list = _li()
B_list = _li()

cum_a = np.cumsum(A_list)
cum_b = np.cumsum(B_list)

ans = 0
for i in range(N):
    if cum_a[i] > K:
        break
    cand = np.searchsorted(cum_b, K - cum_a[i], side="right")
    ans = max(i + 1 + cand, ans)
print(ans)

Submission status: Wrong Answer

Solution code:
class Books:
    def __init__(self, costlist):
        self.ibook = 0
        self.nbook = len(costlist)
        self.costlist = costlist

    def cost(self):
        if self.ibook < self.nbook:
            return self.costlist[self.ibook]
        else:
            return 10000000000

    def nextbook(self):
        self.ibook += 1


n, m, k = map(int, input().split())
listA = list(map(int, input().split()))
listB = list(map(int, input().split()))
A = Books(listA)
B = Books(listB)
time = 0
ans = 0
Acost = A.cost()
Bcost = B.cost()

while time + min(Acost, Bcost) <= k:
    time = time + min(Acost, Bcost)
    ans = ans + 1
    if Acost < Bcost:
        A.nextbook()
    else:
        B.nextbook()
    Acost = A.cost()
    Bcost = B.cost()

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()))
ac = 0
bc = 0
time = 0
for i in range(400000):
    if ac < n:
        if bc < m:
            if a[ac] < b[bc]:
                time += a[ac]
                if time > k:
                    break
                ac += 1
            else:
                time += b[bc]
                if time > k:
                    break
                bc += 1
        else:
            time += a[ac]
            if time > k:
                break
            ac += 1
    elif bc < m:
        time += b[bc]
        if time > k:
            break
        bc += 1
    else:
        break
print(ac+bc)

Submission status: Wrong Answer

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

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

idx=N
ans=0
for i in range(N):
    if A[i]>K:
        idx=i-1
        break

idx2=0
for i in range(idx,-1,-1):
    while idx2<M and A[idx]+B[idx2+1]<=K:
        idx2+=1
    ans=max(ans,i+idx2)

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

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

for i in range(N):
    if A[i]>K:
        idx=i-1
        break

idx2=-1
for i in range(idx,-1,-1):
    while idx2<M-1 and A[idx]+B[idx2+1]<=K:
        idx2+=1
    ans=max(ans,idx+idx2+2)

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

asum=[0]
bsum=[0]
for i in range(n):
    asum.append(asum[i]+a[i])
for i in range(m):
    bsum.append(bsum[i]+b[i])

t=0
for i in range(n+1):
    now=k-asum[i]
    if now<0:
        break
    mini=0
    maxa=m
    cent=(mini+maxa)//2
    bef=-1
    while cent!=bef:
        if now>=bsum[cent]:
            mini=cent
        else :
            maxa=cent
        bef=cent
        cent=(mini+maxa)//2
    if bsum[bef]>=now:
        bef-=1
    elif bsum[bef+1]<=now:
        bef+=1
    if t<i+bef:
        t=i+bef
        
print(t)

Submission status: Wrong Answer

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

asum=[0]
bsum=[0]
for i in range(n):
    asum.append(asum[i]+a[i])
for i in range(m):
    bsum.append(bsum[i]+b[i])

t=0
for i in range(n+1):
    now=k-asum[i]
    if now<0:
        break
    mini=0
    maxa=m
    cent=(mini+maxa)//2
    bef=-1
    while cent!=bef:
        if now>bsum[cent]:
            mini=cent
        else :
            maxa=cent
        bef=cent
        cent=(mini+maxa)//2
    if bsum[bef]>=now:
        bef-=1
    elif bsum[bef+1]<=now:
        bef+=1
    if t<i+bef:
        t=i+bef
        
print(t)

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

an=0
bm=0
t=0
nextab=min(a[an],b[bm])
fab=True
if b[bm]==nextab:
    fab=False

while k>=nextab :
    if fab:
        k-=a[an]
        an+=1
    else:
        k-=b[bm]
        bm+=1
    t+=1
    if an==n and bm==m:
        break
    if an==n:
        nextab=b[bm]
        fab=False
    elif bm==m:
        nextab=a[an]
        fab=True
    else:
        nextab=min(a[an],b[bm])
        fab=True
        if b[bm]==nextab:
            fab=False
print(t)

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
j = 0
count = 0

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

print(count)

Submission status: Wrong Answer

Solution code:
import numpy
import bisect

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

Ac = numpy.cumsum(A)
Bc = numpy.cumsum(B)

ans = 0
for i in range(N):
    n = K - Ac[i]
    if n < 0: break
    tmp = i + 1
    tmp += bisect.bisect_right(Bc, n)
    ans = max(ans, tmp)
#ans = max(ans, bisect.bisect_right(Ac, K), bisect.bisect_right(Bc, K))
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy
import bisect

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

Ac = numpy.cumsum(A)
Bc = numpy.cumsum(B)

ans = 0
for i in range(len(Ac)):
    n = K - Ac[i]
    if n < 0: break
    ans = i + 1
    ans += bisect.bisect_right(Bc, n)
ans = max(ans, bisect.bisect_right(Ac, K), bisect.bisect_right(Bc, K))
print(ans)

Submission status: Wrong Answer

Solution code:
#　変数 n, m, k, arr1, arr2, acum1, acum2, ans

#累積和二つ
#aを回して
#bから条件をみたさないものを引いていく

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

acum1 = [0]
for i in range(n):
    acum1.append( arr1[-1] + arr1[i] )

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

ans = 0
j = m
for i in range(n+1): 
    if acum1[i] > k:
        break
    while acum2[j] > k - acum1[i] and j>0: #なぜwhile?

            j -= 1
    ans = max(ans,i+j)

print(ans)

Submission status: Wrong Answer

Solution code:
#　変数 n, m, k, arr1, arr2, acum1, acum2, ans

#累積和二つ
#aを回して
#bから条件をみたさないものを引いていく

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

acum1 = [0]
for i in range(n):
    acum1.append( arr1[-1] + arr1[i] )

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

ans = 0
j = m
for i in range(n+1): 
    if acum1[i] < k:
        break
    while acum2[j] > k - acum1[i] and j>0: #なぜwhile?

            j -= 1
    ans = max(ans,i+j)

print(ans)

Submission status: Wrong Answer

Solution code:
#　変数 n, m, k, arr1, arr2, acum1, acum2, ans

#累積和二つ
#aを回して
#bから条件をみたさないものを引いていく

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

acum1 = [0]
for i in range(n):
    acum1.append( arr1[-1] + arr1[i] )

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

ans = 0
j = m
for i in range(n+1): 
    if acum1[i] < k:
        break
    while acum2[j] > k - acum1[i] and j>0: #なぜwhile?

            j -= 1
    ans = max(0,i+j)

print(ans)

Submission status: Wrong Answer

Solution code:
#　変数 n, m, k, arr1, arr2, acum1, acum2, ans

#累積和二つ
#aを回して
#bから条件をみたさないものを引いていく

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

acum1 = [0]
for i in range(n):
    acum1.append( arr1[-1] + arr1[i] )

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

ans = 0
j = m
for i in range(n):
    if acum1[i] < k:
        break
    while acum1[i] + acum2[j] > k and acum2[j]>0: #なぜwhile?

            j -= 1
    ans = max(0,i+j)

print(ans)

Submission status: Wrong Answer

Solution code:
#　変数 n, m, k, arr1, arr2, acum1, acum2, ans

#累積和二つ
#aを回して
#bから条件をみたさないものを引いていく

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

acum1 = [0]
for i in range(n):
    acum1.append( arr1[-1] + arr1[i] )

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
# C-Tsundoku

#机AにN冊
#机BにM冊
#制限時間K分

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


sum_time = 0 #読んだ本の合計時間を加算していく
sum_book = 0 #読んだ本の合計冊数を加算していく

A_len = len(A) #リストAの長さ
B_len = len(B) #リストBの長さ

Acou = 0 #リストの添え字に応じて加算
Bcou = 0 #リストの添え字に応じて加算

while (Acou < A_len - 1) and (Bcou < B_len - 1):
	if K <= sum_time:#合計時間が制限時間と同じかそれより以上の場合
		break #処理を終了
	elif A[Acou] <= B[Bcou]:
		sum_time += A[Acou] #一番上のAの本の所要時間を加算
		sum_book += 1 #一冊読んだので加算
		Acou += 1 #選択する本を変更=読んだ本を除外

#		print(sum_time) #経過試験
#		print(sum_book) #経過試験
#		print(Acou)	#経過試験


	elif A[Acou] > B[Bcou]:
		sum_time += B[Bcou] 
		sum_book += 1
		Bcou += 1

#		print(sum_time) #経過試験
#		print(sum_book) #経過試験
#		print(Acou)	#経過試験




if K < sum_time:
	print(sum_book - 1)
elif (Acou < A_len -1) and (Bcou == B_len -1):
	for i in range(Acou,A_len):
		if K <= sum_time:
			break
		else:
			sum_time += A[i]
			sum_book += 1

#		print(sum_time) #経過試験
#		print(sum_book) #経過試験

	print(sum_book - 1)
elif (Acou == A_len - 1) and (Bcou < B_len - 1):
	for i in range(Bcou,B_len):
		if K <= sum_time:
			break
		else:
			sum_time += B[i]
			sum_book += 1


#		print(sum_time) #経過試験
#		print(sum_book) #経過試験

	print(sum_book - 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()))
time=0
sum=0
i=0
j=0
checki=0
checkj=0
while time<k:
    tmp=time
   
    if a[i]<b[j]:
        tmp+=a[i]
        i+=1
    else:
        tmp+=b[j]
        j+=1
    if tmp<=k:
        time=tmp
        sum+=1
    else:
        break
    if i==n and checki!=1:
        a.append(max(b)+1)
        checki=1
    if j==m and checkj!=1:
        b.append(max(a)+1)
        checkj=1
print(sum)

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
sum=0
i=0
j=0
while time<k:
    tmp=time
   
    if a[i]<b[j]:
        tmp+=a[i]
        i+=1
    else:
        tmp+=b[j]
        j+=1
    if tmp<=k:
        time=tmp
        sum+=1
    else:
        break
    if i==n:
        a.append(max(b)+1)
    if j==m:
        b.append(max(a)+1)
print(sum)

Submission status: Wrong Answer

Solution code:
# C-Tsundoku

#机AにN冊
#机BにM冊
#制限時間K分

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


sum_time = 0 #読んだ本の合計時間を加算していく
sum_book = 0 #読んだ本の合計冊数を加算していく

A_len = len(A) #リストAの長さ
B_len = len(B) #リストBの長さ

Acou = 0 #リストの添え字に応じて加算
Bcou = 0 #リストの添え字に応じて加算

while (Acou < A_len - 1) and (Bcou < B_len - 1):
	if K < sum_time:#合計時間が制限時間と同じかそれより以上の場合
		break #処理を終了
	elif A[Acou] <= B[Bcou]:
		sum_time += A[Acou] #一番上のAの本の所要時間を加算
		sum_book += 1 #一冊読んだので加算
		Acou += 1 #選択する本を変更=読んだ本を除外
	elif A[Acou] > B[Bcou]:
		sum_time += B[Bcou] 
		sum_book += 1
		Bcou += 1

if K < sum_time:
	print(sum_book)
elif (Acou < A_len -1) and (Bcou == B_len -1):
	for i in range(Acou,A_len):
		if K < sum_time:
			break
		else:
			sum_time += A[i]
			sum_book += 1
	print(sum_book)
elif (Acou == A_len - 1) and (Bcou < B_len - 1):
	for i in range(Bcou,B_len):
		if K < sum_time:
			break
		else:
			sum_time += B[i]
			sum_book += 1
	print(sum_book)

Submission status: Wrong Answer

Solution code:
anum,bnum,acc = map(int,input().split())
alist = list(map(int,input().split()))
blist = list(map(int,input().split()))


ans = 0;a = 0;b = 0
while sum(alist[:a+1]) < acc:
    if a == anum:
        break
    a += 1

while sum(alist[:a]+blist[:b+1]) < acc:
    if b == bnum:
        break
    b += 1

if a == 0 and b == 0:
    pass
else:
    ans = a+b
    for i in range(1,a):
        while sum(alist[:a-i]+blist[:b+1]) < acc:
            if b == bnum:
                break
            b += 1
            if a + b > ans:
                ans = a + 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()))

a, b = [0], [0]
for i in range(N):
    a.append(a[i] + A[i])
for i in range(M):
    b.append(b[i] + B[i])

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

Submission status: Wrong Answer

Solution code:
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())))
LEN = len(a)+len(b)
ans = 0
count = 0
a_len = len(a)
b_len = len(b)
a_i = 0
b_i = 0
while True:
    MIN = min(a[a_i],b[b_i])
    if MIN == a[a_i]:
        ans+=a[a_i]
        a_i+=1
        if a_i == a_len:
            a[a_i-1]=10**10
            a_i-=1
    elif MIN == b[b_i]:
        ans+=b[b_i]
        b_i+=1
        if b_i == b_len:
            b[b_i-1]=10**10
            b_i-=1
    if k < ans:
        break
    count+=1
print(count)

Submission status: Wrong Answer

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

books_on_a = list(map(int, input().split()))
books_on_b = list(map(int, input().split()))

num_read_books = 0
reading_time = 0

index_a = 0
index_b = 0

for _ in range(n + m):
    if index_a < n:
        time_a = books_on_a[index_a]
    else:
        time_a = float('inf')

    if index_b < m:
        time_b = books_on_b[index_b]
    else:
        time_b = float('inf')

    if time_a < time_b:
        index_a = index_a + 1
        time = time_a
    else:
        index_b = index_b + 1
        time = time_b

    reading_time = reading_time + time

    if reading_time > k:
        break

    num_read_books = num_read_books + 1

print(num_read_books)

Submission status: Wrong Answer

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

books_on_a = list(map(int, input().split()))
books_on_b = list(map(int, input().split()))

num_read_books = 0
reading_time = 0

books = books_on_a + books_on_b

books.sort()

for book in books:
    reading_time = reading_time + book

    if k < reading_time:
        break

    num_read_books = num_read_books + 1

print(num_read_books)

Submission status: Wrong Answer

Solution code:
N,M,K = input().split()

N = int(N)
M = int(M)
K = int(K)

A = list(input().split())
A = [int(c) for c in A]

Sum_A = [0]
ele_A = 0
a = 0

while Sum_A[-1] + A[a] <= K:
    ele_A += A[a]
    a += 1
    Sum_A.append(ele_A)
    if a == len(A):
        break

B = list(input().split())
B = [int(c) for c in B]

Sum_B = [0]
ele_B = 0
b = 0

while Sum_B[-1] + B[b] <= K:
    ele_B += B[b]
    b += 1
    Sum_B.append(ele_B)
    if b == len(B):
        break

h = len(Sum_A) - 1
i = 0
j = 0

while h > 0:
    while Sum_A[h] + Sum_B[i] <= K:
        j = max(j,h + i)
        if i == len(Sum_B) - 1:
            break
        i += 1
    h -= 1

print(j)

Submission status: Wrong Answer

Solution code:
N,M,K = input().split()

N = int(N)
M = int(M)
K = int(K)

A = list(input().split())
A = [int(c) for c in A]

Sum_A = [0]
ele_A = 0
a = 0

while Sum_A[-1] + A[a] <= K:
    ele_A += A[a]
    a += 1
    Sum_A.append(ele_A)
    if a == len(A):
        break

B = list(input().split())
B = [int(c) for c in B]

Sum_B = [0]
ele_B = 0
b = 0

while Sum_B[-1] + B[b] <= K:
    ele_B += B[b]
    b += 1
    Sum_B.append(ele_B)
    if b == len(B):
        break

h = len(Sum_A) - 1
i = 0
j = 0

while h > 0:
    while Sum_A[h] + Sum_B[i] <= K:
        j = max(j,h + i)
        i += 1
        if i == len(Sum_B) - 1:
            break
    if i == len(Sum_B) - 1:
        j = max(j,h + i)
        break
    h -= 1

print(j)

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
sys.setrecursionlimit(2147483647)
input=sys.stdin.readline

def main():
  d = deque()
  N, M, K = map(int, input().split(' '))
  A = deque(map(int, input().split(' ')))
  B = deque(map(int, input().split(' ')))

  for i in range(1, len(A)):
    A[i] = A[i-1] + A[i]
  for i in range(1, len(B)):
    B[i] = B[i-1] + B[i]
  ans, i = 0, N-1
  for j in range(M):
    if(K < B[j]):
      break
    while(i >= 0 and K < B[j] + A[i]):
      i -= 1
    ans = max(ans, i+j+2)
  print(ans)

if __name__=='__main__':
  main()

Submission status: Wrong Answer

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

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

cumA = [0] * (N+1)
cumB = [0] * (M+1)

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

def check(X):
    res = 1e9
    for i in range(N+1):
        j = X - i
        if j < 0 or M < j: continue
        if(cumA[i] + cumB[j] < res):
            res = cumA[i] + cumB[j]
    return res <= K

ok = 0
ng = N + M + 1

while ng - ok > 1:
    mid = (ok + ng) // 2
    if(check(mid)): ok = mid
    else: ng = mid

print(ok)

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 = [0] * (N + 1)
for i in range(N):
    a[i + 1] = a[i] + A[i]

b = [0] * (M + 1)
for i in range(M):
    b[i + 1] = b[i] + B[i]

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

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(" ")))
time = 0
count = 0
x = 0
y = 0

if A[0] > K or B[0] > K:
    print(0)

else:
    for i in range(x,N):
        if time > K:
            break
        for j in range(y,M):
            if time > K:
                break
            else:
                x = i
                y = j
                if A[i] <= B[j]:
                    time += A[i]
                    count += 1
                    break
                else:
                    time += B[j]
                    count += 1
                    continue

    if time < K:
        if x == N - 1:
            for k in range(y, M):
                count += 1
                time += B[k]
                if time >= K:
                    break
                else:
                    continue
        
        if y == M - 1:
            for l in range(x, N):
                count += 1
                time += A[l]
                if time >= K:
                    break
                else:
                    continue
        print(count)
    
    else:
        print(count - 1)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
A, B = [], []
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A.reverse()
B.reverse()
time = 0
max_books = 0
ia, ib = 0, 0
for i in range(N+M):
  max_books += 1
  if A and B:
    if A[-1] > B[-1]:
      time += B.pop()
    else:
      time += A.pop()
  elif A and not B:
    time += A.pop()
  else:
    time += B.pop()
  if time == K:
    print(max_books)
    break
  elif time > K:
    print(max_books-1)
    break

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

C = [0]
D = [0]
for a in A:
    C.append(C[-1] + a)
for b in B:
    D.append(D[-1] + b)

p = n
for i in range(n + 1):
    if C[i] > k:
        p = i - 1
        break

_max = 0
keep = 0
for i in range(p, -1, -1):
    for j in range(keep, m + 1):
        if C[i] + D[j] > k:
            _max = i + j - 1
            keep = j
            break
print(_max)

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

C = [0]
D = [0]
for a in A:
    C.append(C[-1] + a)
for b in B:
    D.append(D[-1] + b)

p = 0
while True:
    if C[p] > k:
        break
    elif p < len(C) - 1:
        p += 1
        continue
    break

_max = 0
for i in range(p, 0, -1):
    for j in range(m + 1):
        if C[i] + D[j] > k:
            break
        elif _max < i + j:
            _max = i + j
print(_max)

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(A,B)
A_=[0]
B_=[0]
t=0
for i in A:
    t+=i
    A_.append(t)
t=0
for j in B:
    t+=j
    B_.append(t)
#print(A_,B_)
for n in range(N+1):
    if A_[n]>K:
        n-=1
        break
#print(n)
ans=n
t=0
for i in range(n,0,-1):
    for m in range(t,M+1):
#        print(B_[m],K-A_[i])
        if B_[m] > K-A_[i]:
            m-=1
            break
    t=m
    ans=max(ans,n+t)
#    print(ans)
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()))
counta = 0
countb = 0
time = 0
book = 0
test = 0

for i in range(0, n + m):
  if counta == n and k >= time + b[countb]:
    time += b[countb]
    countb += 1
  elif countb == m and k >= time + a[counta]:
    time += a[counta]
    counta += 1
  elif counta < n and countb < m:
    if a[counta] < b[countb] and k >= time + a[counta]:
      time += a[counta]
      counta += 1
    elif a[counta] >= b[countb] and k >= time + b[countb]:
      time += b[countb]
      countb += 1
    else:
      break
  else:
    break

print(counta + countb)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

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

a_time_list = list(map(int, input().split()))

b_time_list = list(map(int, input().split()))

total_time = 0
count = 0

while total_time < k:
    if len(a_time_list) == 0 and len(b_time_list) == 0:
        break

    if len(a_time_list) == 0:
        if total_time + b_time_list[0] <= k:
            total_time += b_time_list.pop(0)
        else:
            break
    elif len(b_time_list) == 0:
        if total_time + a_time_list[0] <= k:
            total_time += a_time_list.pop(0)
        else:
            break
    else:
        if a_time_list[0] <= b_time_list[0] and total_time + a_time_list[0] <= k:
            total_time += a_time_list.pop(0)
        elif a_time_list[0] > b_time_list[0] and total_time + b_time_list[0] <= k:
            total_time += b_time_list.pop(0)
        else:
            break

    count += 1

print(count)