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 = map(int,input().split())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    import itertools
    sum_a = list(itertools.accumulate(a))
    sum_b = list(itertools.accumulate(b))
    if sum_a[-1] + sum_b[-1] <= k:
        print(n+m)
        return
    if a[0] > k and b[0] > k:
        print(0)
        return

    for i in range(n-1, -1, -1):
        if sum_a[i] <= k:
            break

    s_a = i
    now_sum = sum_a[s_a]
    for i in range(m):
        if now_sum + sum_b[i] > k:
            break
    s_b = i - 1
    if s_b >= 0:
        now_sum += sum_b[s_b]
    ans = s_a + 1 + s_b + 1
    now_sum = 0
    for a_i in range(s_a-1, -2, -1):
        for b_i in range(s_b+1,m):
            if a_i < 0:
                now_sumtime = sum_b[b_i]
            else:
                now_sumtime = sum_a[a_i] + sum_b[b_i]

            if b_i == m-1 and now_sumtime <= k:
                now_sum = a_i + m
                break
            if now_sumtime > k:
                now_sum = a_i + b_i + 1
                break
        s_b = b_i
        ans = max(ans, now_sum)
    print(ans)

if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n,m,k = map(int,input().split())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    import itertools
    sum_a = list(itertools.accumulate(a))
    sum_b = list(itertools.accumulate(b))
    if sum_a[-1] + sum_b[-1] <= k:
        print(n+m)
        return
    if a[0] > k and b[0] > k:
        print(0)
        return

    for i in range(n-1, -1, -1):
        if sum_a[i] <= k:
            break

    s_a = i
    now_sum = sum_a[s_a]
    for i in range(m):
        if now_sum + sum_b[i] > k:
            break
    s_b = i - 1
    if s_b >= 0:
        now_sum += sum_b[s_b]
    ans = s_a + 1 + s_b + 1
    now_sum = 0
    for a_i in range(s_a-1, -1, -2):
        for b_i in range(s_b+1,m):
            if a_i < 0:
                now_sumtime = sum_b[b_i]
            else:
                now_sumtime = sum_a[a_i] + sum_b[b_i]

            if b_i == m-1 and now_sumtime <= k:
                now_sum = a_i + m
                break
            if now_sumtime > k:
                now_sum = a_i + b_i + 1
                break
        s_b = b_i
        ans = max(ans, now_sum)
    print(ans)

if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n,m,k = map(int,input().split())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    import itertools
    sum_a = list(itertools.accumulate(a))
    sum_b = list(itertools.accumulate(b))
    if sum_a[-1] + sum_b[-1] <= k:
        print(n+m)
        return
    if a[0] > k and b[0] > k:
        print(0)
        return

    for i in range(n-1, -1, -1):
        if sum_a[i] <= k:
            break

    s_a = i
    now_sum = sum_a[s_a]
    for i in range(m):
        if now_sum + sum_b[i] > k:
            break
    s_b = i - 1
    if s_b >= 0:
        now_sum += sum_b[s_b]
    ans = s_a + 1 + s_b + 1
    now_sum = 0
    for a_i in range(s_a-1, -1, -1):
        for b_i in range(s_b,m):
            now_sumtime = sum_a[a_i] + sum_b[b_i]

            if b_i == m-1 and now_sumtime <= k:
                now_sum = a_i + m
                break
            if now_sumtime > k:
                now_sum = a_i + b_i + 1
                break
        s_b = b_i
        ans = max(ans, now_sum)
    print(ans)

if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n,m,k = map(int,input().split())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    import itertools
    sum_a = list(itertools.accumulate(a))
    sum_b = list(itertools.accumulate(b))
    if sum_a[-1] + sum_b[-1] <= k:
        print(n+m)
        return
    if a[0] > k and b[0] > k:
        print(0)
        return

    for i in range(n-1, -1, -1):
        if sum_a[i] <= k:
            break

    s_a = i
    now_sum = sum_a[s_a]
    for i in range(m):
        if now_sum + sum_b[i] > k:
            break
    s_b = i - 1
    if s_b >= 0:
        now_sum += sum_b[s_b]
    ans = s_a + 1 + s_b + 1
    now_sum = 0
    for a_i in range(s_a-1, -1, -1):
        for b_i in range(s_b+1,m):
            now_sumtime = sum_a[a_i] + sum_b[b_i]

            if b_i == m-1 and now_sumtime <= k:
                now_sum = a_i + m
                break
            if now_sumtime > k:
                now_sum = a_i + b_i + 1
                break
        s_b = b_i
        ans = max(ans, now_sum)
    print(ans)

if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n,m,k = map(int,input().split())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    import itertools
    sum_a = list(itertools.accumulate(a))
    sum_b = list(itertools.accumulate(b))
    if sum_a[-1] + sum_b[-1] <= k:
        print(n+m)
        return
    if a[0] > k and b[0] > k:
        print(0)
        return

    for i in range(n-1, -1, -1):
        if sum_a[i] <= k:
            break

    s_a = i
    now_sum = sum_a[s_a]
    for i in range(m):
        if now_sum + sum_b[i] > k:
            break
    s_b = i - 1
    if s_b >= 0:
        now_sum += sum_b[s_b]
    ans = s_a + 1 + s_b + 1
    for a_i in range(s_a-1, -1, -1):
        for b_i in range(s_b+1,m):
            now_sum = sum_a[a_i] + sum_b[b_i]

            if b_i == m-1 and now_sum <= k:
                now_sum = a_i + m
                break
            if now_sum > k:
                now_sum = a_i + b_i + 1
                break
        s_b = b_i
        ans = max(ans, now_sum)
    print(ans)

if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import deque

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

que1 = deque(a)
que2 = deque(b)

point = 0
count = 0
 
while 1:

    try:
        ctp1 = que1.popleft()
    except IndexError:
        que1.appendleft(float('inf'))
    try:
        ctp2 = que2.popleft()
    except IndexError:
        que2.appendleft(float('inf'))

    if ctp1 > ctp2:
        point += ctp2
        que1.appendleft(ctp1)
        if point <= k:
            count += 1
        else:
            break

    elif ctp2 > ctp1:
        point += ctp1
        que2.appendleft(ctp2)
        if point <= k:
            count += 1
        else:
            break

print(count)

Submission status: Wrong Answer

Solution code:
def main():
    n,m,k = map(int,input().split())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    import itertools
    sum_a = list(itertools.accumulate(a))
    sum_b = list(itertools.accumulate(b))
    if sum_a[-1] + sum_b[-1] <= k:
        print(n+m)
        return
    if a[0] > k and b[0] > k:
        print(0)
        return

    for i in range(n-1, -1, -1):
        if sum_a[i] < k:
            break

    s_a = i
    now_sum = sum_a[s_a]
    for i in range(m):
        if now_sum + sum_b[i] > k:
            break
    s_b = i - 1
    if s_b >= 0:
        now_sum += sum_b[s_b]
    ans = s_a + 1 + s_b + 1
    for a_i in range(s_a-1, -1, -1):
        for b_i in range(s_b+1,m):
            now_sum = sum_a[a_i] + sum_b[b_i]
            if now_sum > k:
                now_sum = a_i + b_i + 1
                break
        s_b = b_i
        ans = max(ans, now_sum)
    print(ans)

if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
def resolve():
    M, N, K = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))

    count = 0
    for m in range(1, M+1):
        sumA = sum(a[:m])
        if sumA > K:
            break
        for n in range(1, N+1):
            sumB = sum(b[:n])
            if sumB > K:
                break
            if (sumA + sumB) <= K:
                count = max(count, m + n)
            else:
                break
    print(count)

if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
def resolve():
    M, N, K = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))

    count = 0
    for m in range(1, M+1):
        for n in range(1, N+1):
            if (sum(a[:m] + b[:n]) <= K):
                count = max(count, m + n)
    print(count)

if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
v = list(map(int, input().split()))
u = list(map(int, input().split()))
i = j = ans = 0
while k > 0 and (i < n or j < m):
    if i == n or (j < m and v[i] >= u[j]):
        k -= u[j]
        j += 1
    else:
        k -= v[i]
        i += 1
    ans += k >= 0
print(ans)

Submission status: Wrong Answer

Solution code:
def resolve():
    M, N, K = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))

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

    count = 0
    for m in range(1, M+1):
        for n in range(1, N+1):
            if (A[m-1] + B[n-1] <= K):
                count = max(count, m + n)
    print(count)

if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
def resolve():
    M, N, K = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))

    m = 0
    n = 0
    count = 0
    while(m < M or n < N):
        if (m < M and a[m] > K) and (n < N and b[n] > K):
            break
        if m == M:
            K -= b[n]
            n += 1
        elif n == N:
            K -= a[m]
            m += 1
        elif a[m] < b[n]:
            K -= a[m]
            m += 1
        else:
            K -= b[n]
            n += 1
        count += 1
    print(count)

if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
values = [i for i in input().split(" ")]
booksN = [j for j in input().split(" ")]
booksM = [j for j in input().split(" ")]
sum_time = 0
flag = 0
while sum_time < int(values[2]):
    if booksM and booksN:
        if int(booksM[0]) < int(booksN[0]):
            sum_time += int(booksM[0])
            booksM.pop(0)
        else:
            sum_time += int(booksN[0])
            booksN.pop(0)
    elif booksN:
        sum_time += int(booksN[0])
        booksN.pop(0)
    elif booksM:
        sum_time += int(booksM[0])
        booksM.pop(0)
    else:
        break
    flag += 1
if sum_time > int(values[2]):
    flag -= 1
print(flag)

Submission status: Wrong Answer

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

jikan = 0
while jikan <= k:
    if len(tanaA) != 0 and len(tanaB) != 0:
        if int(tanaA[0]) >= int(tanaB[0]):
            jikan += int(tanaB[0])
            if jikan <= k:
                tanaB.pop(0)
        elif int(tanaA[0]) < int(tanaB[0]):
            jikan += int(tanaA[0])
            if jikan <= k:
                tanaA.pop(0)
    elif len(tanaA) == 0 and len(tanaB) != 0:
        jikan += int(tanaB[0])
        if jikan <= k:
            tanaB.pop(0)
    elif len(tanaB) == 0 and len(tanaA) != 0:
        jikan += int(tanaA[0])
        if jikan <= k:
            tanaA.pop(0)
    elif len(tanaA) == 0 and len(tanaB) == 0:
        break

print(n+m-int(len(tanaA))-int(len(tanaB)))

Submission status: Wrong Answer

Solution code:
x, y, z = map(int, input().split())
lx = list(map(int, input().split()))
nx = lx[0]
ly = list(map(int, input().split()))
ny = ly[0]
a = 0

while nx <= z or ny <= z:
  if nx <= ny:
    z = z-nx
    lx.pop(0)
    if not lx:
      nx = z+1  
    else:
      nx = lx[0]
    a = a+1
  else:
    z = z-ny
    ly.pop(0)
    if not ly:
      ny = z+1
    else:
      ny = ly[0]
    a = a + 1  
print(a)

Submission status: Wrong Answer

Solution code:
import bisect

def main():
    J = [int(_) for _ in input().split()]
    N = J[0]
    M = J[1]
    K = J[2]
    A = [int(_) for _ in input().split()]
    B = [int(_) for _ in input().split()]
    BB = []
    # インクリメント＋2分探索
    tmp = 0
    for i in B:
        tmp = tmp + i
        BB.append(tmp)

    result = 0
    tmp = 0
    for numA in range(0, len(A)):
        tmp = tmp + A[numA]
        if K - tmp < 0:
            continue
        ind = bisect.bisect_right(BB, K - tmp) + numA + 1
        if ind > result:
            result = ind

    print(result)        


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
x=input().split()
N=int(x[0])
M=int(x[1])
K=int(x[2])
A=input().split()
B=input().split()
A.append("200001")
B.append("200001")

a=0
for i in range(N+M):
  if int(A[0])<=int(B[0]):
    K=K-int(A[0])
    if K<0:
      break
    else:
      a+=1
      A.pop(0)
  elif int(B[0])<int(A[0]):
    K=K-int(B[0])
    if K<0:
      break
    else:
      a+=1
      B.pop(0)
print(a)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import math
import bisect
N, M, K = map(int,input().split())
#N = int(input())
#K = int(input())
#S = input()
ans = 0
flg = True
#l = list(map(int,input().split()))
A = list(map(int,input().split()))
B = list(map(int,input().split()))

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

na = bisect.bisect_right(A, K)
#print(na)
for i in range(na-1):
    time_b = K-A[i]
    nb = bisect.bisect_right(B, time_b)
    ans = max(ans, i+nb+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()))

ruiseki_A = [0]
ruiseki_B = [0]

for i in range(len(A)):
    ruiseki_A.append(ruiseki_A[i]+A[i])
for i in range(len(B)):
    ruiseki_B.append(ruiseki_B[i]+B[i])
#print(ruiseki_A)

ans = 0
for i in range(len(ruiseki_A)):
    tmp = K - ruiseki_A[i]
    if tmp < 0:
        continue
    r = len(B)
    l = 0
    while r-l > 1:
        mid = (r + l) // 2
        if ruiseki_B[mid] <= tmp:
            l = mid
        else:
            r = mid
    ans = max(ans, i+l)

print(ans)

Submission status: Wrong Answer

Solution code:
def easy_Greedy():
    NMK=input().split(" ")
    N,M,K=int(NMK[0]),int(NMK[1]),int(NMK[2])
    A=input().split(" ")
    A=[int(i) for i in A]
    B=input().split(" ")
    B=[int(i) for i in B]
    time=0
    book=0
    while(True):
        if len(A)>0 and len(B)>0:
            mintime=min(A[0],B[0])
        elif len(A)>0:
            mintime=A[0]
        elif len(B)>0:
            mintime=B[0]
        else:
            break
    
        if K-time<mintime:
            break
        else:
            time+=mintime
            if len(A)>0 and mintime==A[0]:
                A=A[1:]
            else:
                B=B[1:]
            book+=1
    print(book)

if __name__ == "__main__":
    easy_Greedy()

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import math
import bisect
N, M, K = map(int,input().split())
#N = int(input())
#K = int(input())
#S = input()
ans = 0
flg = True
#l = list(map(int,input().split()))
A = list(map(int,input().split()))
B = list(map(int,input().split()))

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

na = bisect.bisect_left(A, K)
#print(na)
for i in range(na-1):
    time_b = K-A[i]
    nb = bisect.bisect_left(B, time_b)
    ans = max(ans, i+nb+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()))
tim = 0
a = 0
b = 0
ans = 0
f = False #K分を超えている状態 -> True

#両方残っている場合
while a != N and b != M:
    if A[a] < B[b]:
        if tim + A[a] > K:
            f = True
            break
        else:
            tim += A[a]
            a += 1
            ans += 1
    else:
        if tim + B[b] > K:
            f = True
            break
        else:
            tim += B[b]
            b += 1
            ans += 1

#片方残っている場合
if (not f) and a != N:
    while a != N:
        if tim + A[a] > K:
            f = True
            break
        else:
            tim += A[a]
            a += 1
            ans += 1

if (not f) and b != M:
    while b != M:
        if tim + B[b] > K:
            f = True
            break
        else:
            tim += B[b]
            b += 1
            ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
n,m,k = map(int,input().split())
a_ls = list(map(int, input().split()))
b_ls = list(map(int, input().split()))
a_csum = np.cumsum(a_ls)
b_csum = np.cumsum(b_ls)
def isOK(index, key, l):
    if l[index] > key:
        return True
    else:
        return False
def binary_search(l, key):
    '''
    key以上の値を持つ最小のインデックスを返す
    '''
    left = -1
    right = len(l)

    while (right - left) > 1:
        mid = left + (right - left) // 2
        # 直感的に記憶　
            # 「含まれている」んだったら「含むを許容（等号付き）する右側」はmidまで動かして問題ない
                # 新しいrightの位置がkeyの位置だとしても、「含む」は許容されてる
            # 「含まれていない」んだったら「含まない(<)左の壁」をそこまで動かしてもkeyを通り過ぎることはない
        if isOK(mid, key, l):
            right = mid
        else:
            left = mid
    
    # whileを抜ける時、rightとleftは一個差で、かつkeyがrightの位置にある
    return right
ans = 0
for i in range(n):
    rest = k - a_csum[i]
    if rest < 0:
        break
    ind = binary_search(b_csum, rest)
    canread_b = max(0,ind)
    canread = i+1 + canread_b
    ans = max(canread, ans)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
n,m,k = map(int,input().split())
a_ls = list(map(int, input().split()))
b_ls = list(map(int, input().split()))
a_queue = deque(a_ls)
b_queue = deque(b_ls)
time = [0] * (n+m)
for i in range(n+m):
    if a_queue and b_queue:
        if a_queue[0] < b_queue[0]:
            time[i] = a_queue.popleft()
        else:
            time[i] = b_queue.popleft()
    elif a_queue:
        time[i] = a_queue.popleft()
    elif b_queue:
        time[i] = b_queue.popleft()
rest = k
i = 0
while i <= n+m-1 and rest - time[i] >= 0 :
    rest -= time[i]
    i += 1
print(i)

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()))
ruia=[0]
ruib=[0]
mx=0
for (i,j) in zip(a,range(n)):
  ruia.append(ruia[j]+i)

for (i,j) in zip(b,range(m)):
  ruib.append(ruib[j]+i)
ans=0
for i in range(n+1):
  if ruia[i] > k:
    break
  while ruib[j] > k - ruia[i]:
    m -= 1
  ans = max(ans, i + m)
print(ans)

Submission status: Wrong Answer

Solution code:
[N,M,K]=list(map(int,input().split()))
L_A=list(map(int,input().split()))
L_B=list(map(int,input().split()))
S_A = []
S_B = []
S = 0
for i in range(N):
    if S + L_A[i] <= K:
        S += L_A[i]
        S_A.append(S)
    else:
        break
S = 0
for i in range(M):
    if S + L_B[i] <= K:
        S += L_B[i]
        S_B.append(S)
    else:
        break
a = len(S_A)
b = len(S_B)
if a * b == 0:
  print(a+b)
elif S_A[-1] + S_B[-1] <= K:
    print(a+b)
else:
    ans = a
    for i in range(b):
        if S_A[-1] + S_B[i] > K:
            ans += i
    for j in range(a-1,-1,-1):
        if j + b + 1 <= ans:
            break
        if S_A[j] + S_B[ans-j-1] <= K:
            k = ans-j-1
            for x in range(k,b+1,1):
                if S_A[j] + S_B[x] > K:
                    ans = j + x + 2
                    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()))
ruia=[0]
ruib=[0]
mx=0
for (i,j) in zip(a,range(n)):
  ruia.append(ruia[j]+i)

for (i,j) in zip(b,range(m)):
  ruib.append(ruib[j]+i)

for i in range(n,-1,-1):
  ans=-1
  if ruia[i]>k:
    continue
  for j in range(mx,m):
    if ruia[i]+ruib[j]>k:
      break
    ans=i+j
  else:
    ans=i+m
  if ans>mx:
    mx=ans
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()))
ruia=[0]
ruib=[0]
mx=0
for (i,j) in zip(a,range(n)):
  ruia.append(ruia[j]+i)

for (i,j) in zip(b,range(m)):
  ruib.append(ruib[j]+i)

for i in range(n,-1,-1):
  ans=-1
  if ruia[i]>k:
    continue
  for j in range(mx,m):
    if ruia[i]+ruib[j]>k:
      ans=i+j-1
      break
  else:
    ans=i+m
  if ans>mx:
    mx=ans
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()))
ruia=[0]
ruib=[0]
mx=0
for (i,j) in zip(a,range(n)):
  ruia.append(ruia[j]+i)

for (i,j) in zip(b,range(m)):
  ruib.append(ruib[j]+i)

for i in range(n,-1,-1):
  ans=-1
  if ruia[i]>k:
    continue
  for j in range(m):
    if ruia[i]+ruib[j]>k:
      ans=i+j-1
      break
  else:
    ans=i+m
  if ans>mx:
    mx=ans
print(mx)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
while k > 0:
    if b == []:
        k -= a.pop(0)
        ans += 1
    elif a == []:
        k -= b.pop(0)
        ans += 1
    elif a[0] < b[0] and k - a[0] >= 0:
        k -= a.pop(0)
        ans += 1
    elif a[0] >= b[0] and k - b[0] >= 0:
        k -= b.pop(0)
        ans += 1
    else:
        break
print(ans)

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

count = 0
a = A.popleft()
b = B.popleft()
while True:
    if a <= b and k >= a:
        k -= a
        if len(A) != 0:
            a = A.popleft()
        else:
            a = 99999999999999
    elif a > b and k >= b:
        k -= b
        if len(B) != 0:
            b = B.popleft()
        else:
            b = 999999999999999
    else:
      break
    count += 1
print(count)

Submission status: Wrong Answer

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

#配列の最後に番兵法として要素の上限値+1を格納
A.append(1e+9 +1)
B.append(1e+9 +1)

i=0
j=0
while(1):
    t = min(A[i],B[j])
    #print("t=",t)
    if K < t:
        break

    if t == A[i]:
        K -= A[i]
        i += 1
        #print("i=",i)

    else:
        K -= B[j]
        j += 1
        #print("j=",j)

print(i+j)

Submission status: Wrong Answer

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

#配列の最後に番兵法として要素の上限値を格納
A.append(1e+9)
B.append(1e+9)

i=0
j=0
while(1):
    t = min(A[i],B[j])
    #print("t=",t)
    if K < t:
        break

    if t == A[i]:
        K -= A[i]
        i += 1
        #print("i=",i)

    else:
        K -= B[j]
        j += 1
        #print("j=",j)

print(i+j)

Submission status: Wrong Answer

Solution code:
#C
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
A = [0]
B = [0]
#読書時間A,B
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-1
#Aを増やしたときA+Bがkより小さくなるようなi,jを決めて最大値を決めてる
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:
import bisect
N,M,K = map(int, input().split())
A_s = list(map(int, input().split()))
B_s = list(map(int, input().split()))
A_ruiseki = []
B_ruiseki = []
for i, A in enumerate(A_s):
    if i == 0:
        A_ruiseki.append(A_s[i])
    else:
        A_ruiseki.append(A_s[i-1]+A_s[i])
for i, B in enumerate(B_s):
    if i == 0:
        B_ruiseki.append(B_s[i])
    else:
        B_ruiseki.append(B_s[i-1]+B_s[i])
answer = 0
for i, A in enumerate(A_ruiseki):
    if K - A < 0:
        continue
    s = bisect.bisect_right(B_ruiseki, K-A)
    if s == 0:
        continue
    # print(s)
    if answer < s + i + 1:
        answer = s + i + 1
print(answer)

Submission status: Wrong Answer

Solution code:
import bisect
N,M,K = map(int, input().split())
A_s = list(map(int, input().split()))
B_s = list(map(int, input().split()))
A_ruiseki = []
B_ruiseki = []
for i, A in enumerate(A_s):
    if i == 0:
        A_ruiseki.append(A_s[i])
    else:
        A_ruiseki.append(A_s[i-1]+A_s[i])
for i, B in enumerate(B_s):
    if i == 0:
        B_ruiseki.append(B_s[i])
    else:
        B_ruiseki.append(B_s[i-1]+B_s[i])
answer = 0
for i, A in enumerate(A_ruiseki):
    if K - A <= 0:
        continue
    s = bisect.bisect_right(B_ruiseki, K-A)
    if s == 0:
        continue
    # print(s)
    if answer < s + i + 1:
        answer = s + i + 1
print(answer)

Submission status: Wrong Answer

Solution code:
import bisect
N,M,K = map(int, input().split())
A_s = list(map(int, input().split()))
B_s = list(map(int, input().split()))
A_ruiseki = []
B_ruiseki = []
for i, A in enumerate(A_s):
    if i == 0:
        A_ruiseki.append(A_s[i])
    else:
        A_ruiseki.append(A_s[i-1]+A_s[i])
for i, B in enumerate(B_s):
    if i == 0:
        B_ruiseki.append(B_s[i])
    else:
        B_ruiseki.append(B_s[i-1]+B_s[i])
answer = 0
for i, A in enumerate(A_ruiseki):
    if K - A <= 0:
        continue
    s = bisect.bisect_right(B_ruiseki, K-A)
    # print(s)
    if answer < s + i + 1:
        answer = s + i + 1
print(answer)

Submission status: Wrong Answer

Solution code:
import bisect
N,M,K = map(int, input().split())
A_s = list(map(int, input().split()))
B_s = list(map(int, input().split()))
A_ruiseki = []
B_ruiseki = []
for i, A in enumerate(A_s):
    if i == 0:
        A_ruiseki.append(A_s[i])
    else:
        A_ruiseki.append(A_s[i-1]+A_s[i])
for i, B in enumerate(B_s):
    if i == 0:
        B_ruiseki.append(B_s[i])
    else:
        B_ruiseki.append(B_s[i-1]+B_s[i])
answer = 0
for i, A in enumerate(A_ruiseki):
    if K - A < 0:
        continue
    s = bisect.bisect_right(B_ruiseki, K-A)
    # print(s)
    if answer < s + i + 1:
        answer = s + i + 1
print(answer)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
list_a=[]
list_b=[]

list_a=list(map(int,input().split()))
list_b=list(map(int,input().split()))

list_a.extend(list_b)

list_a.sort()

#ここまでは正常#

sum=0
count=0
for i in range(0,len(list_a)):
  if sum<=k and sum+list_a[i]<=k:
    sum+=list_a[i]
    count+=1
  else:
    break

print(count)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
list_a=[]
list_b=[]

list_a=list(map(int,input().split()))
list_b=list(map(int,input().split()))

list_a.extend(list_b)

list_a.sort()

#ここまでは正常#

sum=0
count=0
for i in range(0,len(list_a)):
  if sum<=k and sum+list_a[i]<k:
    sum+=list_a[i]
    count+=1
  else:
    break

print(count)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
list_a=[]
list_b=[]

list_a=list(map(int,input().split()))
list_b=list(map(int,input().split()))

list_a.extend(list_b)

list_a.sort()

#ここまでは正常#

sum=list_a[0]
count=0
i=0
for i in range(0,len(list_a)):
  if sum<k:
    sum+=list_a[i]
    count+=1

print(count)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
list_a=[]
list_b=[]

list_a=list(map(int,input().split()))
list_b=list(map(int,input().split()))

list_a.extend(list_b)

list_a.sort()

sum=0
count=0
while sum<k:
  sum+=list_a[count]
  count+=1

print(count-1)

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
        break
    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


    elif A[0] < B[0]:
        temp = A.pop(0)
        if sum + int(temp) > K:

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

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[n] < B[m]:
            time += A[n]
            if time > K:
                break
            n += 1
        else:
            time += B[m]
            if time > K:
                break
            m += 1
    elif m == M:
        time += A[n]
        if time > K:
            break
        n += 1
    elif n == N:
        time += B[m]
        if time > K:
            break
        m += 1
    
print(n + m)