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

suma = [a[0]]
sumb = [b[0]]

for i in range(1, n):
    suma.append(suma[i-1] + a[i])

for i in range(1, m):
    sumb.append(sumb[i-1] + b[i])

nowmax = 0
j = m-1
for i in range(n):

    while j >= 0 and suma[i] + sumb[j] > k:
        j -= 1

    if j >= 0 and a[i] + sumb[j] <= k:
        nowmax = max(nowmax, i + j + 2)

    else:
        break

print(nowmax)

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 = [a[0]]
sumb = [b[0]]

for i in range(1, n):
    suma.append(suma[i-1] + a[i])

for i in range(1, m):
    sumb.append(sumb[i-1] + b[i])

nowmax = 0
j = m-1
for i in range(n):

    while j >= 0 and suma[i] + sumb[j] > k:
        j -= 1

    if j >= 0:
        nowmax = max(nowmax, i + j + 2)

    else:
        break

print(nowmax)

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

cnt = 0
i = 0
j = 0
while k >= 0:
    if i >= len(a) and j >= len(b):
        break

    if i >= len(a):
        if k >= b[j]:
            k -= b[j]
            j += 1
            cnt += 1
        else:
            break
        continue

    if j >= len(b):
        if k >= a[i]:
            k -= a[i]
            i += 1
            cnt += 1
        else:
            break
        continue

    if a[i] <= b[j]:
        if k >= a[i]:
            k -= a[i]
            i += 1
            cnt += 1
        else:
            break
    else:
        if k >= b[j]:
            k -= b[j]
            j += 1
            cnt += 1
        else:
            break

print(cnt)

Submission status: Wrong Answer

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

cnt = 0
i = 0
j = 0
while k >= 0:
    if i >= len(a) and j >= len(b):
        break

    if i >= len(a):
        if k >= b[j]:
            k -= b[j]
            j += 1
            cnt += 1
        else:
            break
        continue

    if j >= len(b):
        if k >= a[i]:
            k -= a[i]
            i += 1
            cnt += 1
        else:
            break
        continue

    if a[i] >= b[j]:
        if k >= a[i]:
            k -= a[i]
            i += 1
            cnt += 1
        else:
            break
    else:
        if k >= b[j]:
            k -= b[j]
            j += 1
            cnt += 1
        else:
            break

print(cnt)

Submission status: Wrong Answer

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

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:
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
    #print('i:{0}, j:{1}'.format(i, j))
    ans = max(ans, i + j)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import itertools as it

input = sys.stdin.readline

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

AS = list(it.accumulate([0]+A))
BS = list(it.accumulate([0]+B))
max_value = 0
for i in range(N+1):
    if AS[i] >= K:
        continue
    ok, ng = 0, M+1
    while ng - ok > 1:
        mid = (ok + ng) // 2
        time = AS[i] + BS[mid]
        if time <= K:
            ok = mid
        else:
            ng = mid
    num = i + ok
    if num > max_value:
        max_value = num
print(max_value)

Submission status: Wrong Answer

Solution code:
import bisect


def main():
    N, M, K = map(int, input().split())
    A = [int(v) for v in input().split()]
    B = [int(v) for v in input().split()]
    ruisekiA = [0 for _ in range(N+1)]
    ruisekiB = [0 for _ in range(M+1)]
    for i in range(N):
        ruisekiA[i + 1] = ruisekiA[i] + A[i]
    for i in range(M):
        ruisekiB[i + 1] = ruisekiB[i] + B[i]

    ans = 0
    # A を i 個 使う
    for i in range(N+1):
        tans = i
        tk = K - ruisekiA[i]
        if tk < K:
            continue
        idx = bisect.bisect_left(ruisekiB, tk)
        if M+1 == idx or ruisekiB[idx] != tk:
            idx -= 1
        tans += idx
        ans = max(ans, tans)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import bisect

def main():
    N, M, K = map(int, input().split())
    A = [int(v) for v in input().split()]
    B = [int(v) for v in input().split()]
    C = [v1+v2 for v1, v2 in zip(A[:min(N, M)], B[:min(N, M)])]
    ruisekiA = [0 for _ in range(N+1)]
    ruisekiB = [0 for _ in range(M+1)]
    ruisekiC = [0 for _ in range(min(N, M)+1)]
    for i in range(len(C)):
        ruisekiA[i + 1] = ruisekiA[i] + A[i]
        ruisekiB[i + 1] = ruisekiB[i] + B[i]
        ruisekiC[i + 1] = ruisekiC[i] + C[i]

    ans = 0
    # i番目までは両方読む
    for i in range(min(N, M)+1):
        tans = i * 2
        tk = K - ruisekiC[i]
        if tk < 0:
            continue

        # A だけ、Bだけで何冊読めるか考える
        idx_a = bisect.bisect_left(ruisekiA[:N+1], tk + ruisekiA[i])
        if idx_a == len(ruisekiA) or ruisekiA[idx_a] != tk + ruisekiA[i]:
            idx_a -= 1
        idx_b = bisect.bisect_left(ruisekiB[:M+1], tk + ruisekiB[i])
        if idx_b == len(ruisekiB) or ruisekiB[idx_b] != tk + ruisekiB[i]:
            idx_b -= 1
        ans = max(ans, max(tans+idx_a-i, tans+idx_b-i))
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import bisect

def main():
    N, M, K = map(int, input().split())
    A = [int(v) for v in input().split()]
    B = [int(v) for v in input().split()]
    if N < M:
        for _ in range(M-N):
            A.append(0)
    else:
        for _ in range(N-M):
            B.append(0)
    C = [v1+v2 for v1, v2 in zip(A, B)]
    ruisekiA = [0 for _ in range(len(C)+1)]
    ruisekiB = [0 for _ in range(len(C)+1)]
    ruisekiC = [0 for _ in range(len(C)+1)]
    for i in range(len(C)):
        ruisekiA[i + 1] = ruisekiA[i] + A[i]
        ruisekiB[i + 1] = ruisekiB[i] + B[i]
        ruisekiC[i + 1] = ruisekiC[i] + C[i]

    ans = 0
    # i番目までは両方読む
    for i in range(len(C)+1):
        tans = i * 2
        tk = K - ruisekiC[i]
        if tk < 0:
            continue

        # A だけ、Bだけで何冊読めるか考える
        idx_a = bisect.bisect_left(ruisekiA, tk + ruisekiA[i])
        if idx_a == len(ruisekiA) or ruisekiA[idx_a] != tk + ruisekiA[i]:
            idx_a -= 1
        idx_b = bisect.bisect_left(ruisekiB, tk + ruisekiB[i])
        if idx_b == len(ruisekiB) or ruisekiB[idx_b] != tk + ruisekiB[i]:
            idx_b -= 1
        ans = max(ans, max(tans+idx_a-i, tans+idx_b-i))
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def resolve():
    M, N, K = list(map(int, input().strip().split()))
    A = list(map(int, input().strip().split())) # list
    B = list(map(int, input().strip().split())) # list

    ans = 0

    while K >= 0 and (A or B):
        if not B or (A and A[0] <= B[0]):
            if K < A[0]:
                break
            K -= A.pop(0)
        elif not A or (B and A[0] > B[0]):
            if K < B[0]:
                break
            K -= B.pop(0)

        ans += 1

    print(ans)


if __name__ == "__main__":
	resolve()

Submission status: Wrong Answer

Solution code:
import bisect

def main():
    N, M, K = map(int, input().split())
    A = [int(v) for v in input().split()]
    B = [int(v) for v in input().split()]
    if N < M:
        for _ in range(M-N):
            A.append(0)
    else:
        for _ in range(N-M):
            B.append(0)
    C = [v1+v2 for v1, v2 in zip(A, B)]
    ruisekiA = [0 for _ in range(len(C)+1)]
    ruisekiB = [0 for _ in range(len(C)+1)]
    ruisekiC = [0 for _ in range(len(C)+1)]
    for i in range(len(C)):
        ruisekiA[i + 1] = ruisekiA[i] + A[i]
        ruisekiB[i + 1] = ruisekiB[i] + B[i]
        ruisekiC[i + 1] = ruisekiC[i] + C[i]

    ans = 0
    # i番目までは両方読む
    for i in range(len(C)+1):
        tans = i * 2
        tk = K - ruisekiC[i]
        if tk < 0:
            continue

        # A だけ、Bだけで何冊読めるか考える
        idx_a = bisect.bisect_left(ruisekiA, tk + ruisekiA[i]+0.1) - 1
        idx_b = bisect.bisect_left(ruisekiB, tk + ruisekiB[i]+0.1) - 1
        ans = max(ans, max(tans+idx_a-i, tans+idx_b-i))
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    N, N, K = map(int, input().split())
    A = [int(v) for v in input().split()]
    B = [int(v) for v in input().split()]
    A.append(10**10)
    B.append(10**10)
    cur_a = 0
    cur_b = 0
    ans = 0
    while True:
        if A[cur_a] < B[cur_b]:
            if A[cur_a] <= K:
                ans += 1
                K -= A[cur_a]
                cur_a += 1
            else:
                break
        else:
            if B[cur_b] <= K:
                ans += 1
                K -= B[cur_b]
                cur_b += 1
            else:
                break
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    N, N, K = map(int, input().split())
    A = [int(v) for v in input().split()]
    B = [int(v) for v in input().split()]
    A.append(10**9+1)
    B.append(10**9+1)
    cur_a = 0
    cur_b = 0
    ans = 0
    while True:
        if A[cur_a] < B[cur_b]:
            if A[cur_a] <= K:
                ans += 1
                K -= A[cur_a]
                cur_a += 1
            else:
                break
        else:
            if B[cur_b] <= K:
                ans += 1
                K -= B[cur_b]
                cur_b += 1
            else:
                break
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from itertools import zip_longest, count, accumulate
from bisect import bisect, bisect_left

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

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

num = 0

for i, a in enumerate(a):
    time_rest = k - a
    
    if time_rest < 0:
        continue
    
    num = max(num, i + bisect_left(b, time_rest))

print(num)

Submission status: Wrong Answer

Solution code:
import sys
import heapq
sys.setrecursionlimit(10 ** 8)

def Z(): return int(input())
def ZZ(): return [int(_) for _ in input().split()]

def main():
    N, M, K = ZZ()
    A = ZZ()
    B = ZZ()
    k = 0
    for i in range(N):
        if k + A[i] <= K: k += A[i]
        else: break
    else: i += 1
    ans = i
    for j in range(M):
        if k + B[j] <= K: k += B[j]
        else: break
    else: j += 1
    ans += j
    for ii in range(1, i+1):
        k -= A[i-ii]
        i -= 1
        while j < M and k + B[j] <= K:
            k += B[j]
            j += 1
        ans = max(ans, i+j)
    print(ans)


    return

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()))
time=0
a,b=0,0

if K>=sum(A)+sum(B):
  print(N+M)
else:
  A.append(1000000000000000)
  B.append(1000000000000000)
  while time<=K:
    if A[a]<=B[b]:
      time+=A[a]
      #print(f"A{A[a]}")
      a+=1
    else:
      time+=B[b]
      #print(f"B{B[b]}")
      b+=1
  print(a+b-1)

Submission status: Wrong Answer

Solution code:
import sys
import heapq
sys.setrecursionlimit(10 ** 8)

def Z(): return int(input())
def ZZ(): return [int(_) for _ in input().split()]

def main():
    N, M, K = ZZ()
    A = ZZ()
    B = ZZ()
    l = list()
    heapq.heapify(l)
    ans = 0
    i = j = k = 0
    heapq.heappush(l, [A[i], 0])
    heapq.heappush(l, [B[j], 1])
    i += 1
    j += 1
    while k <= K and l:
        q, r = heapq.heappop(l)
        if k + q <= K:
            k += q
            ans += 1
        else:
            break
        if r == 0:
            if i < N:
                heapq.heappush(l, [A[i], 0])
                i += 1
        else:
            if j < M:
                heapq.heappush(l, [B[j], 1])
                j += 1
    print(ans)

    return

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from bisect import *

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

a_b=[0]
for i in range(1,n+1):
  a_b.append(a_b[i-1]+a[i-1])

b_b=[0]
for i in range(1,m+1):
  b_b.append(b_b[i-1]+b[i-1])

ans=0
for i in range(n+1):
  t_ans=i
  if t_ans>k:
    break
  t_ans+=bisect_right(b_b,k-a_b[i])-1
  ans=max(ans,t_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()))


count = 0
j = 0

for i in range(N + M):
  if len(A) == 0 and len(B) == 0:
    count = N + M
  if len(A) == 0:
    j = B[0]
    del B[0]
  elif len(B) == 0:
    j = A[0]
    del A[0]
  elif A[0] <=  B[0]:
    print("A"+str(i))
    j = A[0]
    del A[0]
  else:
    print("B"+str(i))
    j = B[0]
    del B[0]
  if j <= K:
    K -= j
    count += 1
print(count)

Submission status: Wrong Answer

Solution code:
from bisect import *
import numpy as np
import sys
input = sys.stdin.readline

def main():
    N, M, K = list(map(int, input().split()))
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    A = np.cumsum(np.array(A))
    B = np.cumsum(np.array(B))

    ans = 0

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

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

C = A + B
C.sort()

count = 0

for i in C:
  if i <= K:
    K -= i
    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()))
a=A[0]
b=sum(B)
count=a+b
p=0
x=0
for i in range(N):
    while count>K:
        count-=B[M-1]
        M-=1
    if i!=N-1:
        a+=A[i+1]
    p=max(p,i+M+1)
    if a>K:
        break
print(p)

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=A[0]
b=sum(B)
count=a+b
p=0
x=0
for i in range(N):
    while count>=K:
        count-=B[M-1]
        M-=1
    if i!=N-1:
        a+=A[i+1]
    p=max(p,i+M+1)
    if a>K:
        break
print(p)

Submission status: Wrong Answer

Solution code:
# vim: fileencoding=utf-8


def main():
    k = int(input().split()[2])
    a = [int(x) for x in input().split()]
    b = [int(x) for x in input().split()]
    r = 0
    while True:
        read = 0
        if len(a) != 0 and len(b) != 0:
            ai = a.index(min(a))
            bi = b.index(min(b))
            if sum(a[: ai + 1]) < sum(b[: bi + 1]):
                read = a[0]
                a = a[1:]
            else:
                read = b[0]
                b = b[1:]
        elif len(a) == 0:
            read = b[0]
            b = b[1:]
        elif len(b) == 0:
            read = a[0]
            a = a[1:]
        else:
            break
        k -= read
        if k < 0:
            break
        r += 1
        if k == 0:
            break
    print(r)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# vim: fileencoding=utf-8


def main():
    k = int(input().split()[2])
    a = [int(x) for x in input().split()]
    b = [int(x) for x in input().split()]
    r = 0
    while True:
        read = 0
        if len(a) != 0 and len(b) != 0:
            ai = a.index(min(a))
            bi = b.index(min(b))
            sa = sum(a[: ai + 1])
            sb = sum(b[: bi + 1])
            if sa < sb:
                read = a[0]
                a = a[1:]
            else:
                read = b[0]
                b = b[1:]
        elif len(a) == 0:
            bi = b.index(min(b))
            sb = sum(b[: bi + 1])
            read = b[0]
            b = b[1:]
        elif len(b) == 0:
            ai = a.index(min(a))
            sa = sum(a[: ai + 1])
            read = a[0]
            a = a[1:]
        else:
            break
        k -= read
        if k < 0:
            break
        r += 1
        if k == 0:
            break
    print(r)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# vim: fileencoding=utf-8


def main():
    k = int(input().split()[2])
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    r = 0
    while True:
        read = 0
        if len(a) != 0 and len(b) != 0:
            ai = a.index(min(a))
            bi = b.index(min(b))
            sa = sum(a[: ai + 1])
            sb = sum(b[: bi + 1])
            if sa < sb:
                read = a[0]
                a = a[1:]
            else:
                read = b[0]
                b = b[1:]
        elif len(a) == 0:
            bi = b.index(min(b))
            sb = sum(b[: bi + 1])
            read = b[0]
            b = b[1:]
        elif len(b) == 0:
            ai = a.index(min(a))
            sa = sum(a[: ai + 1])
            read = a[0]
            a = a[1:]
        else:
            break
        k -= read
        if k < 0:
            break
        r += 1
        if k == 0:
            break
    print(r)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# vim: fileencoding=utf-8


def main():
    n, m, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    r = 0
    while True:
        read = 0
        if len(a) != 0 and len(b) != 0:
            ai = a.index(min(a))
            bi = b.index(min(b))
            sa = sum(a[: ai + 1])
            sb = sum(b[: bi + 1])
            if sa < sb:
                read = a[0]
                a = a[1:]
            else:
                read = b[0]
                b = b[1:]
        elif len(a) == 0:
            bi = b.index(min(b))
            sb = sum(b[: bi + 1])
            read = b[0]
            b = b[1:]
        else:
            ai = a.index(min(a))
            sa = sum(a[: ai + 1])
            read = a[0]
            a = a[1:]
        k -= read
        if k < 0:
            break
        r += 1
        if k == 0:
            break
    print(r)


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()))
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])
print(a)
print(b)
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:
N,M,K = list(map(int,input().split()))
A = list(map(int,input().split()))
B = list(map(int,input().split()))
p = []
i=0
j=0
while sum(p) < K and i<len(A) and j<len(B):
    if A[i] < B[j]:
        p.append(A[i])
        i+=1
    else:
        p.append(B[j])
        j+=1
if i==len(A):
    while sum(p)<K and j < len(B):
        p.append(B[j])
        j+=1
if j == len(B):
    while sum(p)<K and i < len(A):
        p.append(A[i])
        i+=1
if sum(p)>K:
    p.pop()

print(len(p))

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()))
p = []
i=0
j=0
while sum(p) < K and i<len(A) and j<len(B):
    if A[i] < B[j]:
        p.append(A[i])
        i+=1
    else:
        p.append(B[j])
        j+=1
if i==len(A):
    while sum(p)<K:
        p.append(B[j])
        j+=1
if j == len(B):
    while sum(p)<K:
        p.append(A[i])
        i+=1
if sum(p)>K:
    p.pop()
print(len(p))

Submission status: Wrong Answer

Solution code:
import numpy as np

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

ak=[]
bk=[]
wk=0
for i in a:
    wk+=i
    if wk<k:
        ak.append(wk)
ass=len(ak)
wk=0
for i in b:
    wk+=i
    if wk<k:
        bk.append(wk)
bs=len(bk)
an=ass
j=0
for i in range(ass-1,-1,-1):
    while bk[j]+ak[i]<=k:
        j+=1
        an=max(an,i+1+j)
        if j>=bs:
            j=0
            break

an=max(an,ass)
an=max(an,bs)

print(an)

Submission status: Wrong Answer

Solution code:
import bisect, numpy
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
B=numpy.cumsum(B)
ans=0
for i in range(1,N+1):
  books=0
  tmp=sum(A[:i])
  K-=tmp
  if K>0:
    if i>0:books+=i
    else:books=0
    books+=bisect.bisect_right(B,K)+1
    ans=max(ans,books)
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=a+b
c.sort()
i=0
sum=0
flag=0
while i<(n+m):
  sum=sum+c[i]
  i=i+1
  if sum<=k:
    flag=flag+1
  else:
    break
print(flag)

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=a+b
c.sort()
i=0
sum=0
while sum<k:
  sum=sum+c[i]
  i=i+1
print(i-1)

Submission status: Wrong Answer

Solution code:
import bisect

N, M, K = input().split()

desk1 = list(map(int, input().split()))
desk2 = list(map(int, input().split()))

max_time = int(K)
item1 = [0]
item2 = [0]
for i in desk1:
    item1.append(item1[-1] + i)
for i in desk2:
    item2.append(item2[-1] + i)

ret = 0
for i, t in enumerate(item1):
    remain_time = max_time - t
    if remain_time > 0:
        j = bisect.bisect(item2, remain_time) - 1
        if j < 0:
            j = 0
        ret = max(ret, i + j)
    else:
        ret = max(ret, i)
print(ret)

Submission status: Wrong Answer

Solution code:
import bisect

N, M, K = input().split()

desk1 = list(map(int, input().split()))
desk2 = list(map(int, input().split()))

max_time = int(K)
item1 = [0]
item2 = [0]
for i in desk1:
    item1.append(item1[-1] + i)
for i in desk2:
    item2.append(item2[-1] + i)
ret = 0
for i, t in enumerate(item1):
    remain_time = max_time - t
    if remain_time > 0:
        j = bisect.bisect(item2, remain_time) - 1
        #print(i,remain_time, j)
        ret = max(ret, i + j)

print(ret)

Submission status: Wrong Answer

Solution code:
import numpy as np

n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
wk=0
aa=[]
bb=[]
for i in a:
    wk+=i
    aa.append(wk)
wk=0
for i in b:
    wk+=i
    bb.append(wk)
ak=np.array(aa)
bk=np.array(bb)

ass=np.count_nonzero(ak<=k)
bs= np.count_nonzero(bk<=k)
i=0
bs=0
an=0

for i in range(ass-1,-1,-1):
    wk=np.count_nonzero(bk<=(k-ak[i]))
    an=max(an,(i+1+wk))
an=max(an,ass)
an=max(an,bs)

print(an)

Submission status: Wrong Answer

Solution code:
# aで読む冊数を固定して、bで何冊読めるか考える
# 累積和にしておく、読めるbの冊数は2分探索で求める
# 計算時間はO(N*logM)


import itertools
import bisect

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

# aとbの累積和を計算
# accumulateオブジェクトをリストに変換
a_cumsum = list(itertools.accumulate(a))
b_cumsum = list(itertools.accumulate(b))


# 読める本の冊数を記録しておくリスト
books = []


# aの冊数を0冊~最大までそれぞれ固定して、bの冊数を求める
for minute in a_cumsum:
    minutes = 0
    numbers = 0
    
    minutes += minute
    
    if minutes <= k:

        # aの冊数を計算
        numbers += a_cumsum.index(minute)

        # 残り時間
        rest_minutes = k - minutes
        
        # bの冊数を計算
        if b_cumsum[-1] == rest_minutes:
            b_books = len(b_cumsum) - 1
        else:
            # bisect.bisect_leftは、リストのどこに数値を入れ込めるかのインデックスを返す（右の）
            b_books = bisect.bisect_left(b_cumsum, rest_minutes)
            b_books -= 1
    
        numbers += b_books
    
    books.append(numbers)

print(max(books))

Submission status: Wrong Answer

Solution code:
import itertools
from bisect import bisect
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A_sum = list(itertools.accumulate(A))
B_sum = list(itertools.accumulate(B))
ans = 0
for i, num in enumerate(A_sum):
    target = K - num
    if target < 0:
        break
    j = bisect(B_sum, target)
    ans = max(ans, (i+1)+j)
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
from bisect import bisect
N, M, K = map(int, input().split())
A = tuple(map(int, input().split()))
B = tuple(map(int, input().split()))
A_sum = tuple(itertools.accumulate(A))
B_sum = tuple(itertools.accumulate(B))
ans = 0
for i, num in enumerate(A_sum):
    target = K - num
    if target <= 0:
        break
    j = bisect(B_sum, target)
    ans = max(ans, (i+1)+j)
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
from bisect import bisect
N, M, K = map(int, input().split())
A = tuple(map(int, input().split()))
B = tuple(map(int, input().split()))
A_sum = tuple(itertools.accumulate(A))
B_sum = tuple(itertools.accumulate(B))
B_table = set(B_sum)
ans = 0
for i, num in enumerate(A_sum):
    target = K - num
    if target < 0:
        break
    j = bisect(B_sum, target)
    ans = max(ans, (i+1)+j)
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
import bisect
N, M, K = map(int, input().split())
A = tuple(map(int, input().split()))
B = tuple(map(int, input().split()))
A_sum = tuple(itertools.accumulate(A))
B_sum = tuple(itertools.accumulate(B))
B_table = set(B_sum)
ans = 0
for i, num in enumerate(A_sum):
    target = K - num
    if target < 0:
        break
    if target in B_table:
        j = bisect.bisect_left(B_sum, target)
        ans = max(ans, (i+1)+(j+1))
    else:
        j = bisect.bisect_left(B_sum, target)
        ans = max(ans, (i+1)+j)
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
import bisect
N, M, K = map(int, input().split())
A = tuple(map(int, input().split()))
B = tuple(map(int, input().split()))
A_sum = tuple(itertools.accumulate(A))
B_sum = tuple(itertools.accumulate(B))
ans = 0
for i, num in enumerate(A_sum):
    target = K - num
    if target < 0:
        target, i = 0, -1
    if target in set(B_sum):
        j = bisect.bisect_left(B_sum, target)
        ans = max(ans, (i+1)+(j+1))
    else:
        j = bisect.bisect_left(B_sum, target)
        ans = max(ans, (i+1)+j)
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
import bisect
N, M, K = map(int, input().split())
A = tuple(map(int, input().split()))
B = tuple(map(int, input().split()))
A_sum = tuple(itertools.accumulate(A))
B_sum = tuple(itertools.accumulate(B))
ans = 0
for i, num in enumerate(A_sum):
    target = K - num
    if target < 0:
        target, i = 0, -1
    if target in B_sum:
        j = bisect.bisect_left(B_sum, target)
        ans = max(ans, (i+1)+(j+1))
    else:
        j = bisect.bisect_left(B_sum, target)
        ans = max(ans, (i+1)+j)
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

ak=np.cumsum(a)
bk=np.cumsum(b)

ass=[k]
h=0
for i in range(n):
    wk=k-ak[i]
    if wk>=0:
        ass.append(wk)
        h=i
    else:
        break
an =0
bma=0
for i in range(m):
    if k>=bk[i]:
        bma=i+1
    else:
        break

for i in range(h+2):
    for j in range(bma):
        if ass[i]>=bk[j]:
            if an <i+j+1:
                an=i+j+1
        else:
            break
print(an)

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

# 非破壊的
book_list = a + b
book_list.sort()

minutes = 0
numbers = 0


for minute in book_list:
    minutes += minute
    if minutes > k:
        break

    numbers += 1

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[0] > limit:
            cur = 0
        else:
            cur = i + 1
        cand = bisect_right(cum2, limit - cum1[i])
        ans = max(cur + 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))

print(search(cum_a, cum_b, N, K))