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

  # nは入力回数
A = list(map(int, input().split()))

B = list(map(int, input().split()))
sum=0
count = 0
# print(A[0],B[0])
for i in range(N+M):
    if len(A)==0:
        for i in range(N+M):
            if len(B) == 0:

                break
            else:
                temp= B.pop(0)
                if sum + int(temp) > K:

                    break
                else:
                    sum += temp
                    count += 1

    elif len(B) == 0:
        for i in range(N+M):
            if len(A) == 0:

                break
            else:
                temp = A.pop(0)
                if sum + int(temp) > K:

                    break
                else:
                    sum += temp
                    count += 1
            break
    elif A[0] >= B[0]:
        temp = B.pop(0)
        if sum+int(temp) > K:

            break
        else:
            sum +=temp
            count += 1


    else:
        temp = A.pop(0)
        if sum + int(temp) > K:

            break
        else:
            sum += temp
            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()))

n_book = 0
time = 0
n = 0   #Aの本を読んだ数
m = 0   #Bの本を読んだ数

while time < K and (n < N or m < M):
    if n < N and m < M:
        if A[0] < B[0]:
            time += A.pop(0)
            if time > K:
                break
            n += 1
        else:
            time += B.pop(0)
            if time > K:
                break
            m += 1
    elif m == M:
        time += A.pop(0)
        if time > K:
            break
        n += 1
    elif n == N:
        time += B.pop(0)
        if time > K:
            break
        m += 1
     
    n_book += 1
    
print(n_book)

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

n_book = 0
time = 0
n = 0   #Aの本を読んだ数
m = 0   #Bの本を読んだ数

while time < K and (n < N or m < M):
    if n < N and m < M:
        if A[0] < B[0]:
            time += A[0]
            if time > K:
                break
            del A[0]
            n += 1
        else:
            time += B[0]
            if time > K:
                break
            del B[0]
            m += 1
    elif m == M:
        time += A[0]
        if time > K:
            break
        del A[0]
        n += 1
    elif n == N:
        time += B[0]
        if time > K:
            break
        del B[0]
        m += 1
     
    n_book += 1
    
print(n_book)

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

summ, count = 0, 0
i, j = 0, 0
while summ < k and i <= n-1 and j <= m-1:
    if a[i] <= b[j]:
        if summ + a[i] <= k:
            summ += a[i]
            i += 1
            count += 1
        else: break
    else:
        if summ+a[i] <= k:
            summ += b[j]
            j += 1
            count += 1
        else: 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()))

n_book = 0
time = 0
n = 0   #Aの本を読んだ数
m = 0   #Bの本を読んだ数

while time < K and (n <= N or m <= M):
    if time + min(A[0], B[0]) > K:
        break

    if n < N and m < M:
        time += min(A[0], B[0])
    elif m == M:
        time += A[0]
    elif n == N:
        time += B[0]
    
    if A[0] < B[0]:
        n += 1
        if len(A) > 1:
            del A[0]
        else:
            A = [1e10]
    else:
        m += 1
        if len(B) > 1:
            del B[0]
        else:
            B = [1e10]
    
    n_book += 1
    
print(n_book)

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

n_book = 0
time = 0

while time < K:
    if time + min(A[0], B[0]) > K:
        break
    time += min(A[0], B[0])
    if A[0] < B[0]:
        if len(A) > 1:
            del A[0]
        else:
            A = [1e10]
    else:
        if len(B) > 1:
            del B[0]
        else:
            B = [1e10]
    n_book += 1

print(n_book)

Submission status: Wrong Answer

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

a_books = list(map(int, input().split()))
b_books = list(map(int, input().split()))

result = 0

while k > 0:
    if a_books and b_books:
        if a_books[0] <= b_books[0]:
            time = a_books.pop(0)
        else:
            time = b_books.pop(0)
    elif a_books and not b_books:
        time = a_books.pop(0)
    elif not a_books and b_books:
        time = b_books.pop(0)
    else:
        break

    if time > k:
        break

    result += 1
    k -= time

print(result)

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

summ = 0
count = 0
i, j = 0, 0
while summ < k and i <= n-1 and j <= m-1:
  if a[i] <= b[j]:
    summ += a[i]
    i += 1
  else:
    summ += b[j]
    j += 1
  count += 1
print(summ)

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()))
ta=sum(a)
a.append(0)
tb=0
ans=0
j=0
for i in range(n+1):
    ta -= a[n-i]
    if ta>k:
        continue
    while tb + ta<k:

        if j ==m:
            ans=max(ans,n-i+j)
            break
        ans=max(ans,n-i+j)
        tb += b[j]
        j +=1

print(ans)

Submission status: Wrong Answer

Solution code:
n, m, k =map(int, input().split())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
ta=sum(a)
a.append(0)
tb=0
ans=0
j=0
for i in range(n+1):
    ta -= a[n-i]
    if ta>k:
        continue
    while tb + ta<k:

        if j ==m:
            ans=max(ans,n-i+j+1)
            break
        tb += b[j]
        ans=max(ans,n-i+j)
        j +=1

print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
from itertools import accumulate

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

A_cumsum = list(accumulate(A))
B_cumsum = list(accumulate(B))

max_books = 0
for a, A_sum in enumerate(A_cumsum, start=1):
    if A_sum > K:
        break
    else:
        b = bisect.bisect(B_cumsum, K - A_sum)
        max_books = max(a + b, max_books)

print(max_books)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate

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

A_cumsum = list(accumulate(A))
B_cumsum = list(accumulate(B))

max_books = 0
for i, A_sum in enumerate(A_cumsum, start=1):
    for j, B_sum in enumerate(B_cumsum, start=1):
        if A_sum + B_sum > K:
            break
        else:
            max_books = max(i + j, max_books)

print(max_books)

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(i+j,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()))
C=list()
D=list()
c=0
d=0
for i in range(n):
    c+=A[i]
    C.append(k-c)
for i in range(m):
    D.append(d+B[i])
    d+=B[i]
ans=0
#C=[i for i in C if i>=0]
for i in range(n):
    now=C[i]
    s=0
    while D[s]<=now:
        s+=1
        if s>=len(D):
            break
    if s>0:
        ans=max(ans,i+s+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()))
C=list()
D=list()
c=0
d=0
for i in range(n):
    c+=A[i]
    C.append(k-c)
for i in range(m):
    D.append(d+B[i])
    d+=B[i]
ans=0
C=[i for i in C if i>=0]
for i in range(len(C)):
    now=C[i]
    s=0
    while D[s]<=now:
        s+=1
        if s>=len(D):
            break
    if s>0:
        ans=max(ans,i+s+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()))
C=list()
D=list()
c=0
d=0
for i in range(n):
    c+=A[i]
    C.append(k-c)
for i in range(m):
    D.append(d+B[i])
    d+=B[i]
ans=0
C=[i for i in C if i>=0]
for i in range(len(C)):
    now=C[i]
    E=list()
    for j in D:
        if j>now:
            break
        elif j<=now:
            E.append(j)
    if len(E)>0:
        ans=max(ans,i+1+len(E))
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()))
C=list()
D=list()
c=0
d=0
for i in range(n):
    c+=A[i]
    C.append(k-c)
for i in range(m):
    D.append(d+B[i])
    d+=B[i]
ans=0
for i in range(n):
    now=C[i]
    E=[j for j in D if j<=now]
    if len(E)>0:
        ans=max(ans,i+1+len(E))
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

N, M, K = [int(s) for s in sys.stdin.readline().split()]
n = 0
A = [0]
for s in sys.stdin.readline().split():
    n = n + int(s)
    A.append(n)

n = 0
B = [0]
for s in sys.stdin.readline().split():
    n = n + int(s)
    B.append(n)

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

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline

N, M, K = [int(s) for s in input().split()]
n = 0
A = [0]
for s in input().split():
    n = n + int(s)
    A.append(n)

n = 0
B = [0]
for s in input().split():
    n = n + int(s)
    B.append(n)

ans = 0
for i in range(N + 1):
    if A[i] > K:
        break
    for j in range(M, 0, -1):
        if A[i] + B[j] <= K:
            if ans <= i + j:
                ans = i + j
            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()))

sumA = [0]
sumB = [0]
tmp = 0
answer = 0
st = 1

for i in range(N):
    tmp = tmp + A[i]
    sumA.append(tmp)

tmp = 0
for i in range(M):
    tmp = tmp + B[i]
    sumB.append(tmp)

for i in range(N, -1, -1):
    booktmp = 0

    for j in range(st, M + 1):

        if sumA[i] + sumB[j] <= K:
            booktmp = i + j
        else:
            st = j
            break
    answer = max(answer, booktmp)


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

sumA = []
sumB = []
tmp = 0
answer = 0
st = 1

for i in range(N):
    tmp = tmp + A[i]
    sumA.append(tmp)

tmp = 0
for i in range(M):
    tmp = tmp + B[i]
    sumB.append(tmp)

for i in range(N, 0, -1):
    booktmp = 0

    for j in range(st, M + 1):

        if sumA[i-1] + sumB[j-1] <= K:
            booktmp = i + j
        else:
            st = j
            break
    answer = max(answer, booktmp)


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

sumA = []
sumB = []
tmp = 0
answer = 0
st = 1

for i in range(N):
    tmp = tmp + A[i]
    sumA.append(tmp)

tmp = 0
for i in range(M):
    tmp = tmp + B[i]
    sumB.append(tmp)

for i in range(N, 0, -1):
    booktmp = 0

    for j in range(st, M + 1):

        if sumA[i-1] + sumB[j-1] <= K:
            booktmp = i + j
            st = st + 1
        else:
            break
    answer = max(answer, booktmp)


print(answer)

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

answer = 0
minutes = 0

for i in range(N+M):
    if len(A) == 0:
        minutes = minutes + B.popleft()
    elif len(B) == 0:
        minutes = minutes + A.popleft()
    else:
        if A[0] > B[0]:
            minutes = minutes + B.popleft()
        else:
            minutes = minutes + A.popleft()

    if minutes <= K:
        answer += 1
    else:
        break

print(answer)

Submission status: Wrong Answer

Solution code:
def main():
        
    N_satu, M_satu, K_fun = map(int, input().split())

    A_fun = list(map(int, input().split()))
    B_fun = list(map(int, input().split()))

    SumOf_A = [0]
    SumOf_B = [0]

    for i in range(N_satu):
        next_val = SumOf_A[i] + A_fun[i]
        SumOf_A.append(next_val)

    for i in range(M_satu):
        next_val = SumOf_B[i] + B_fun[i]
        SumOf_B.append(next_val)

    index_b = 1
    max_cnt = 0

    for a in range(N_satu + 1):
        i_a = N_satu - a
        val_a = SumOf_A[i_a]
        
        if (val_a <= K_fun):
            summ = val_a
            cnt = i_a
            next_sum = summ
            
            
            while (next_sum <= K_fun and index_b <= M_satu):
                next_sum = summ + SumOf_B[index_b]
                
                if (next_sum <= K_fun):
                    cnt += 1
                    index_b += 1
                else:
                    index_b -= 1
                    summ = summ + SumOf_B[index_b]
                    break
            

            max_cnt = max(max_cnt, cnt)

    print(max_cnt)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
        
    N_satu, M_satu, K_fun = map(int, input().split())

    A_fun = list(map(int, input().split()))
    B_fun = list(map(int, input().split()))

    SumOf_A = [0]
    SumOf_B = [0]

    for i in range(N_satu):
        next_val = SumOf_A[i] + A_fun[i]
        SumOf_A.append(next_val)

    for i in range(M_satu):
        next_val = SumOf_B[i] + B_fun[i]
        SumOf_B.append(next_val)

    index_b = 1
    max_cnt = 0

    for a in range(N_satu + 1):
        i_a = N_satu - a
        val_a = SumOf_A[i_a]
        
        if (val_a <= K_fun):
            summ = val_a
            cnt = i_a
            
            while (summ <= K_fun and index_b <= M_satu):
                next_sum = summ + SumOf_B[index_b]
                
                if (next_sum <= K_fun):
                    cnt += 1
                    index_b += 1
                else:
                    index_b -= 1
                    summ = summ + SumOf_B[index_b]
                    break
            

            max_cnt = max(max_cnt, cnt)

    print(max_cnt)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline

N, M, K = [int(s) for s in input().split()]

n = 0
B = [0]
for s in input().split():
    n = n + int(s)
    B.append(n)

ans = 0
a_time = 0
for i, s in enumerate([0] + input().split()):
    a_time = a_time + int(s)
    if i == 1 :
        A_1 = a_time
    if a_time <= K:
        for j, b_time in enumerate(B):
            read_time = a_time + b_time
            if read_time > K:
                if ans <= i + j - 1:
                    ans = i + j - 1
                break
    else:
        break

if ans == 0:
    if A_1 < K:
        ans = N + M
    elif B[1] < K:
        ans = N + M

print(ans)

Submission status: Wrong Answer

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

A_time = [sum(A[0:i+1]) for i in range(len(A))]
B_time = [sum(B[0:i+1]) for i in range(len(B))]

ans = 0
for i, a_time in enumerate(A_time):
    for j, b_time in enumerate(B_time):
        read_time = a_time + b_time
        if read_time <= K:
            if ans <= i + j + 2:
                ans = i + j + 2

print(ans)

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()))
d_A = deque(A)
d_B = deque(B)
sum_time = 0
cnt = 0
while sum_time <= k:
    if len(d_A) != 0 and len(d_B) != 0:
        a = d_A[0]
        b = d_B[0]
        if a < b:
            sum_time += d_A.popleft()
            cnt += 1
        else:
            sum_time += d_B.popleft()
            cnt += 1
        if sum_time > k:
            cnt -= 1
            break
    elif len(d_A) == 0 and len(d_B) != 0:
        sum_time += d_B.popleft()
        cnt += 1
        if sum_time > k:
            cnt -=1
            break
    elif len(d_A) != 0 and len(d_B) == 0:
        sum_time += d_A.popleft()
        cnt += 1
        if sum_time > k:
            cnt -=1
            break
    elif len(d_A) == 0 and len(d_B) == 0:
        break

print(cnt)

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()))
d_A = deque(A)
d_B = deque(B)
sum_time = 0
cnt = 0
while sum_time <= k:
    if len(d_A) != 0 and len(d_B) != 0:
        a = d_A[0]
        b = d_B[0]
        if a < b:
            sum_time += d_A.popleft()
            cnt += 1
        else:
            sum_time += d_B.popleft()
            cnt += 1
        if sum_time > k:
            cnt -=1
    elif len(d_A) == 0 and len(d_B) != 0:
        sum_time += d_B.popleft()
        cnt += 1
        if sum_time > k:
            cnt -=1
    elif len(d_A) != 0 and len(d_B) == 0:
        sum_time += d_A.popleft()
        cnt += 1
        if sum_time > k:
            cnt -=1
    elif len(d_A) == 0 and len(d_B) == 0:
        break

print(cnt)

Submission status: Wrong Answer

Solution code:
import numpy as np
from bisect import bisect_right

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

ans = 0
for a_num, time in enumerate(a):
    if time >= k:
        continue
    b_num = bisect_right(b, k - time)
    num = a_num + b_num + 1
    if num > ans:
        ans = num
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
from bisect import bisect_right

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

ans = 0
for a_num, time in enumerate(a):
    if time > k:
        continue
    b_num = bisect_right(b, k - time)
    num = a_num + b_num + 1
    if num > ans:
        ans = num
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()))
if k >= sum(a) + sum(b):
    print(n + m)
    exit()
ans = -1
total_time = 0
a_cnt = 0
b_cnt = 0
while total_time <= k:
    if a_cnt > len(a) - 1:
        read_time = b[b_cnt]
        b_cnt += 1

    elif b_cnt > len(b) - 1:
        read_time = a[a_cnt]
        a_cnt += 1

    else:
        read_time = min(a[a_cnt], b[b_cnt])
        if read_time == a[a_cnt]:
            a_cnt += 1
        else:
            b_cnt += 1

    total_time += read_time
    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()))
if k >= sum(a) + sum(b):
    print(n + m)
    exit()
ans = -1
total_time = 0
a_cnt = 0
b_cnt = 0
while total_time < k:
    if a_cnt > len(a) - 1:
        read_time = b[b_cnt]
        b_cnt += 1

    elif b_cnt > len(b) - 1:
        read_time = a[a_cnt]
        a_cnt += 1

    else:
        read_time = min(a[a_cnt], b[b_cnt])
        if read_time == a[a_cnt]:
            a_cnt += 1
        else:
            b_cnt += 1

    total_time += read_time
    ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
import bisect

def cumsum(xs):
    result = [xs[0]]
    for x in xs[1:]:
        result.append(result[-1] + x)
    return result

a,b,c=map(int,input().split())
d=list(map(int,input().split()))
e=list(map(int,input().split()))

result=[]
for i in range(min(a,b)):
    o1=min(d[i],e[i])
    o2=max(d[i],e[i])
    result.append(o1)
    result.append(o2)

w=max(d,e,key=len)[min(a,b):max(a,b)]

for i in range(max(a,b)-min(a,b)):
    result.append(w[i])

ans=cumsum(result)

print(bisect.bisect_right(ans,c))

Submission status: Wrong Answer

Solution code:
from itertools import accumulate

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
sa = [0] + list(accumulate(a))
sb = [0] + list(accumulate(b))

ai = 0
for i in range(n + 1):
    if sa[i] > k:
        break
    ai = i
bi = m
ans = 0
for i in range(ai, -1, -1):
    for j in range(bi, -1, -1):
        if sa[i] + sb[j] <= k:
            ans = max(ans, i + j)
            bi = j
            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()))

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

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


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

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

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


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

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

print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import sys

n,m,k = [int(x) for x in stdin.readline().rstrip().split()]
A = [int(x) for x in stdin.readline().rstrip().split()]
B = [int(x) for x in stdin.readline().rstrip().split()]

cc = []
for i in range(n):
    count = i+1
    kk = k
    sumA = sum(A[:i+1])
    kk = kk - sumA

    if kk < 0: break

    for j in range(m):
        kk = kk - B[j]

        if kk < 0:
            cc.append(count)
            break

        count = count + 1

        if j == m-1:
            cc.append(count)
            break

if cc == []:
    print (0)
else:
    print (max(cc))

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
alst = list(map(int, input().split()))
blst = list(map(int, input().split()))
alst.append(2*10**9)
blst.append(2*10**9)
ptime = 0
acou = 0
bcou = 0
books = 0
while True:
    if alst[acou] <= blst[bcou]:
        ptime += alst[acou]
        acou += 1
    else:
        ptime += blst[bcou]
        bcou += 1
    if ptime <= k:
        books += 1
    else:
        break
print(books)

Submission status: Wrong Answer

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

result = 0
while k > 0:
  if a_books and b_books:
    if a_books[0] < b_books[0]:
      time = a_books.pop(0)
    else:
      time = b_books.pop(0)
  elif a_books and not b_books:
    time = a_books.pop(0)
  elif not a_books and b_books:
    time = b_books.pop(0)
  else:
    break
  
  if time <= k:
    result += 1

  k -= time

print(result)

Submission status: Wrong Answer

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

result = 0
while k > 0:
  if a_books and b_books:
    if a_books[0] <= b_books[0]:
      time = a_books.pop(0)
    else:
      time = b_books.pop(0)
  elif a_books and not b_books:
    time = a_books.pop(0)
  elif not a_books and b_books:
    time = b_books.pop(0)
  else:
    break
  
  if time <= k:
    result += 1
    k -= time
  else:
      break


print(result)

Submission status: Wrong Answer

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

total_time = 0
result = 0

for book in books:
  total_time += book
  if total_time <= k:
    result += 1
  else:
    break

print(result)

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]

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

ans = 0

for i in range(N+1):
    if a[i] > K:
        break
    for j in range(M+1):
        if a[i] + b[j] > K:
            ans = max(ans,i + j -1)
            break
        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()))

import numpy as np
A = [0] + A
B = [0] + B
AA = np.cumsum(A)
BB = np.cumsum(B)

ans = 0
jmax = M
for i in range(1, N+1):
    a = AA[i]
    if a > K:
      break
    for j in range(jmax, 0, -1):
        b = BB[j]
        if a + b <= K:
            ans = max(ans, i+j)
            break
    jmax = 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()))

import numpy as np
A = [0] + A
B = [0] + B
AA = np.cumsum(A)
BB = np.cumsum(B)

ans = 0
jmax = M
for i in range(1, N+1):
    a = AA[i]
    for j in range(jmax, 0, -1):
        b = BB[j]
        if a + b <= K:
            ans = max(ans, i+j)
            break
    jmax = 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 = [0]
B = [0]

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

for i in range(M):
    B.append(B[i]+b[i])
ans = 0

t = 100
for i in range(0,N+1):
    p = min(t,M)
    if A[i] > K:
        break
    while B[p] > K - A[i]:
        p -= 1
    t = p
    ans = max(ans,i+p)

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 = [0]
B = [0]

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

for i in range(M):
    B.append(B[i]+b[i])
ans = 0

t = 0
for i in range(0,N+1):
    p = min(t,M)
    if A[i] > K:
        break
    while B[p] > K - A[i]:
        p -= 1
    t = p
    ans = max(ans,i+p)

print(ans)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
a = list(map(int, input().split()))+[float('inf')]
b = list(map(int, input().split()))+[float('inf')]
ans = 0
i, j = 0, 0
while ans <= k:
    if a[i] <= b[j]:
        ans += a[i]
        i += 1
    else:
        ans += b[j]
        j += 1
if ans == float('inf'):
    print(len(a)+len(b)-2)
else:
    print(i+j-1)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
a = list(map(int, input().split()))+[float('inf')]
b = list(map(int, input().split()))+[float('inf')]
ans = 0
i, j = 0, 0
while ans <= k:
    if a[i] <= b[j]:
        ans += a[i]
        i += 1
    else:
        ans += b[j]
        j += 1
if ans == float('inf'):
    print(sum(a[:-1])+sum(b[:-1]))
else:
    print(i+j-1)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
a = list(map(int, input().split()))+[float('inf')]
b = list(map(int, input().split()))+[float('inf')]
ans = 0
i, j = 0, 0
while ans <= k:
    if a[i] <= b[j]:
        ans += a[i]
        i += 1
    else:
        ans += b[j]
        j += 1
print(i+j-1)