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()))
c = 0
a = a[::-1]
b = b[::-1]
a_i = n-1
b_i = m-1
t = 0
while t+min(a[max(a_i, 0)], b[max(b_i, 0)]) <= k:
    if a_i < 0 and b_i >= 0:
        if t+b[b_i] <= k:
            c += 1
            t += b[b_i]
            b_i -= 1
    elif b_i < 0 and a_i >= 0:
        if t+a[a_i] <= k:
            c += 1
            t += a[a_i]
            a_i -= 1
    elif a_i < 0 and b_i < 0:
        break
    elif a[a_i] < b[b_i]:
        c += 1
        t += a[a_i]
        a_i -= 1
    elif a[a_i] > b[b_i]:
        c += 1
        t += b[b_i]
        b_i -= 1
    else:
        break

print(c)

Submission status: Wrong Answer

Solution code:
import math

a, b, k = map(int, input().split())
a_list = list(map(int, input().split()))
a_list  = a_list[::-1]

b_list = list(map(int, input().split()))
b_list  = b_list[::-1]

list_ = []
cnt=0
finish_flg = False
jikan = 0
while (len(a_list)!=0) & (len(b_list)!=0):
  a_top = a_list[-1]
  b_top = b_list[-1]

  if a_top<b_top:
    list_.append(a_top)
    a_list.pop()
  else:
    list_.append(b_top)
    b_list.pop()
    
list_ = list_ + a_list + b_list

while (sum(list_[:cnt+1])<k) & (cnt<len(list_)):
  cnt+=1

print(cnt)

Submission status: Wrong Answer

Solution code:
import itertools
import bisect

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

cA = list(itertools.accumulate(A))
cB = list(itertools.accumulate(B))

#print(cA)
#print(cB)

ans = 0
for i in range(n):
    tmp = cA[-(i+1)]
    if tmp <= k:
        indb = bisect.bisect_left(cB, k - tmp)
        #print(indb)
        ans = max(ans, (n-i)+indb)
    
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n, m, k = map(int, readline().split())
a = list(map(int, readline().split()))
b = list(map(int, readline().split()))
# k = 10
# a = [1, 2, 3, 4]
# b = [1, 1, 1, 9]
if sum(a)+sum(b) <= k:
    print(len(a)+len(b))
    exit()

a = a + ([200010] * 3)
b = b + ([200010] * 3)

t = 0
i = 0
j = 0
ans = 0
while t <= k:
    if a[i] <= b[j]:
        t += a[i]
        i += 1
    elif b[j] < a[i]:
        t += b[j]
        j += 1
    # print("t=", t, 'k=', k)
    if t <= k:
        ans += 1
    # print(t)
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()
num = 0
cnt = 0
for i in range(n+m):
    if c[i]+num <= k:
        num += c[i]
        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()))

i = 0
j = 0
t = 0
c = 0
while 1 == 1:
    if i == n and j == m:
        break
    elif j == m:
        t = t + a[i]
        if t > k:
            break
        c = c + 1
        i = i + 1
    elif i == n:
        t = t + b[j]
        if t > k:
            break
        c = c + 1
        j = j + 1
    elif a[i] <= b[j]:
        t = t + a[i]
        if t > k:
            break
        c = c + 1
        i = i + 1
    else:
        t = t + b[j]
        if t > k:
            break
        c = c + 1
        j = j + 1
print(c)

Submission status: Wrong Answer

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

lis_max = len(lis)
if sum(lis) <= k:
    print(lis_max)
else:
    res = 0
    tim = 0  
    for i in range(lis_max):
        tim += lis[i]
        res += 1
        if tim > k:
            res -= 1
            break
    print(res)

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

book_count = 0
time_count = 0
for i in range(N+M):
    if time_count >= K:
        break
    if len(A) > 0 and len(B) > 0:
        if A[0] > B[0]:
            time_count += B[0]
            B.pop(0)
            book_count += 1
        else:
            time_count += A[0]
            A.pop(0)
            book_count += 1
    elif len(A) == 0 and len(B) > 0:
        time_count += B[0]
        book_count += 1
    elif len(A) > 0 and len(B) == 0:
        time_count += A[0]
        book_count += 1

if book_count < N+M:
    print(book_count-1)
else:
    print(book_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 = [0]
B = [0]
A.extend(a)
B.extend(b)
time = sum(A)
ai = len(A)-1
bi = 0
con = 0
flg = None
if len(a) == 1 and len(b)==1:
    if a[0] + b[0] <= K:
        print(2)
    elif min(a[0],b[0]) <= K:
        print(1)
    else:
        print(0)
else:
    while True:
        #print("---------")
        #print(str(ai)+":"+str(bi))
        if time > K:
            if flg is not None:
                con = max(con,flg-1)
                flg = None
            
            if ai == 0:
                break
            time -=A[ai]
            ai -= 1
        else:
            #print("b")
            flg = ai+bi
            time +=B[bi]
            bi += 1
            if bi == len(B):
                if time > K:
                    pass
                else:
                    con = max(con,ai+bi-1)
                break
        #print(flg)
    print(con)

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


books = sorted(A+B)

cnt=-1

while K >= 0:
  K-=books[cnt]
  cnt+=1


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

read_time = 0
i, j = 0, 0
ct = 0

while True:
    if A[i] <= B[j]:
        read_time += A[i]
        i += 1
    else:
        read_time += B[j]
        j += 1
    if read_time > K:
        break
    ct += 1
    if i > N-1:
        for k in range(j,M):
            read_time += B[k]
            if read_time > K:
                break
            ct += 1
        break
    if j > M-1:
        for k in range(i,N):
            read_time += A[k]
            if read_time > K:
                break
            ct += 1
        break

print(ct)

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()))
AB = 0
A.append(1000000001)
B.append(1000000001)

a = 0
b = 0
x = -1

while K >= AB:
    if a<N-1 and b < M-1:
        if A[a] + A[a+1] < B[b] + B[b+1]:
            AB += A[a]
            a += 1
            x +=1
        else:
            AB += B[b]
            b += 1
            x +=1
    else:
        if A[a] < B[b]:
            AB += A[a]
            a += 1
            x +=1
        else:
            AB += B[b]
            b += 1
            x +=1
print(x)

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

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

time = K
ans = 0
a = 0
b = 0
while True:
    if a >= N or A[a] > K:
        if b >= M-1:
            if B[b] == time:
                ans += 1
            break
        time -= B[b]
        b += 1
    elif b >= M or B[b] > K:
        if a >= N-1:
            if A[a] == time:
                ans += 1
            break
        time -= A[a]
        a += 1
    else:
        if A[a] > K and B[b] > K:
            break
        if(A[a] < B[b]):
            time -= A[a]
            a += 1
        else:
            time -= B[b]
            b += 1
    if time <= 0:
        if time == 0:
            ans += 1
        break
    ans += 1

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()))
A.reverse()
B.reverse()

jikan=0
count=0
while True:
    if len(A)==0 and len(B)==0:
        break

    elif len(A)==0:
        jikan+=B[-1]
        del B[-1]
        if jikan<=K:
            count+=1
        else:
            break

    elif len(B)==0:
        jikan+=A[-1]
        del A[-1]
        if jikan<=K:
            count+=1
        else:
            break
    else:
        if A[-1] <= B[-1]:
            jikan+=A[-1]
            del A[-1]
            if jikan<=K:
                count+=1
            else:
                break
        else:
            jikan+=B[-1]
            del B[-1]
            if jikan<=K:
                count+=1
            else:
                break
    #print('A,B:', A,B)

print(count)

Submission status: Wrong Answer

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

ans = m + n
amin = sum(amins)
bmin = sum(bmins)
mins = amin + bmin

while k < mins:
   if amin < bmin:
      m = bmins.pop()
      bmin -= m
   else:
      m = amins.pop()
      amin -= m
   mins -= m
   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()))

cnt = 0
cost = 0
for i, x in enumerate(a):
    cost += x
    if cost > k:
        cnt = i
        cost -= x
        break
else:
    for j, y in enumerate(b):
        cost += y
        if cost > k:
            cnt = n + j
            cost -= y
            break
    else:
        cnt = n + m

if cnt <= n:
    i_max, j = cnt - 1, 0
else:
    i_max, j = n - 1, cnt - n - 1

while cost + b[j] <= k and j < m - 1:
    j += 1
    cnt += 1
    cost += b[j]

ans = cnt
for i_max in range(i_max, -1, -1):
    if j == m - 1: break
    cost -= a[i]
    cnt -= 1
    while cost + b[j] <= k and j < m - 1:
        j += 1
        cnt += 1
        cost += b[j]
    ans = max(cnt, ans)
    i -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

readline = sys.stdin.buffer.readline


def SS(A, K):
    sA = 0
    AA = []
    for a in A:
        sA += a
        if sA > K:
            break
        AA.append(sA)

    return AA


def main():
    N, M, K = map(int, readline().split())
    A = list(map(int, readline().split()))
    B = list(map(int, readline().split()))

    AA = SS(A, K)
    BB = SS(B, K)
    AA = AA[::-1]

    M = max(len(AA), len(BB))

    left = 0
    right = len(BB) - 1

    while left < len(AA):
        if AA[left] + BB[right] <= K:
            m = len(AA) - left + right + 1
            if m > M:
                M = m
            left += 1
        else:
            right -= 1
            if right < 0:
                break

    print(M)


main()

Submission status: Wrong Answer

Solution code:


def main3():
    n, m, k = map(int, input().split())
    aa = list(map(int, input().split()))
    bb = list(map(int, input().split()))
    time_sum = 0
    counter = 0
    ans = []

    if bb[0] >= aa[0]:
        if k < aa[0]:
            return counter
    if bb[0] <= aa[0]:
        if k < bb[0]:
            return counter

    if (sum(aa)+sum(bb)) <= k:
        return n+m

    for i in range(n+1):
        counter = i
        time_sum = sum(aa[:i])
        if time_sum > k:
            continue
        elif time_sum == k:
            counter += 1
            ans.append(counter)
        else:
            for j in range(m):
                time_sum += bb[j]
                if time_sum > k and j != 0:
                    ans.append(counter)
                    break
                if time_sum > k and j == 0:
                    break
                elif time_sum == k:
                    counter += 1
                    ans.append(counter)
                    break
                else:
                    counter += 1

    ans.sort(reverse=True)
    return ans[0]


if __name__ == '__main__':
    ans = main3()
    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()))

L = [float("inf") for _ in range(N+M+1)] #i行目は(1+i)冊読むのに必要な最小コスト,ｊ列目はそのときの(A, B)
L[0] = 0
L[1] = min(A[0], B[0])
c = 0
a = 0
b = 0

for k in range(len(A)):
    a += A[k]
    A[k] = a
for k in range(len(B)):
    b += B[k]
    B[k] = b

AA = [0] + A

BB = [0] + B


for k in range(1,N+M+1):
    if k <= min(N, M):
        for l in range(k+1):
            if AA[l] + BB[k-l] < L[k]:
                L[k] = AA[l] + BB[k-l]
    if k > min(M,N):
        if M > N:
            for j in range(max(0, k-M), N+1):
                if L[k] > AA[N - j] + BB[k-j]:
                    L[k] = AA[j] + BB[k-j]
                    
        else:
            for j in range(max(0, k - N), M+1):
                if L[k] > AA[k-j] + BB[j]:
                    L[k] = AA[k-j] + BB[j]

for k in range(1, len(L)+1):
    if L[-k] <= K:
        print(len(L)-k)
        break
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
import math  # gcdもあるよ
from collections import deque
from collections import defaultdict
from copy import deepcopy
from itertools import accumulate #リストを与えると累積和を返す
def input(): return sys.stdin.readline().rstrip()
from functools import lru_cache #メモ化

def main():
    n, m, k = list(map(int,sys.stdin.readline().split()))
    a = deque(map(int,sys.stdin.readline().split()))
    b = deque(map(int,sys.stdin.readline().split()))
    ans_book_a = deque([])
    ans_book_b = deque([])
    ans_list = []
    ans = 0

    for _ in range(n):
        if sum(ans_book_a) + int(a[0]) < k:
            ans_book_a.append(a.popleft())
        else: break
        ans += 1
    ans_list.append(ans)
    #print(ans_list)
    while(b != deque([])):
            #print(ans_book_b)

            if sum(ans_book_a) + sum(ans_book_b) + int(b[0]) <= k:
                ans_book_b.append(b.popleft())
                ans += 1
            else: break
    ans_list.append(ans)
    #print(ans_list)
    while(ans_book_a != deque([])):
        #print(ans_book_a)
        ans_book_a.pop()
        ans -= 1
        while(b != deque([])):
            #print(ans_book_b)
            if sum(ans_book_a) + sum(ans_book_b) + int(b[0]) <= k:
                ans_book_b.append(b.popleft())
                ans += 1
            else: break
            #print(ans_book_a, ans_book_b)

        ans_list.append(ans)

    print(max(ans_list))
        
    return 0

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import bisect
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
sa = [0] * (n+1)
for i in range(n):
    sa[i+1] = sa[i] + a[i]
sb = [0] * (m+1)
for i in range(m):
    sb[i+1] = sb[i] + b[i]

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

from collections import deque

time = sum(a)+sum(b)
ans = len(a)+len(b)

a = deque(a[::-1])
b = deque(b[::-1])

while time>k:
    if  sum(a)>sum(b):
        time-=a[0]
        ans-=1
        a.popleft()
    elif sum(a)<sum(b):
        time-=b[0]
        ans-=1
        b.popleft()
    elif sum(a)==sum(b):
        if a[0]>b[0]:
            time-=a[0]
            ans-=1
            a.popleft()
        else:
            time-=b[0]
            ans-=1
            b.popleft()
    else:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
a = input().split()
x = input().split()
y = input().split()
z = x + y
zz = []
zz = list(map(lambda i: int(i), z))
t = 0
for i in range(len(zz)):
  if t > int(a[2]):
    break
  t += sorted(zz)[i]
print(t)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
la=list(map(int,input().split()))
lb=list(map(int,input().split()))
lla=[]
counta=0
for i in la:
    counta+=i
    lla.append(counta)
countb=0
llb=[]
for j in lb:
    countb+=j
    llb.append(countb)
for i in range(n):
    if lla[i]>k:
        break
if lla[n-1]<=k:
    book=n
    num=n-1
elif lla[n-1]>k and i==n-1:
    book=n-1
    num=n-2
else:
    num=i
    book=i+1
num=i
while num>=0 and book<m+n and book-num-1<=m-1:
    if num!=0:
        if lla[num]+llb[book-num-1]<=k:
            book+=1
        else:
            num-=1
    elif num==0:
        if llb[book-num-1]<=k:
            book+=1
        else:
            num-=1

print(book)

Submission status: Wrong Answer

Solution code:
from collections import deque

def main(N, M, K, A, B):
    k = K   # 制限時間
    n = N
    m = M

    que_A = deque(A)
    que_B = deque(B)

    a = que_A.popleft()
    b = que_B.popleft()

    while k >= 0 and (m != 0 or n != 0):
        if m == 0:
            k -= a
            if n > 1:
                a = que_A.popleft()
            n -= 1
        elif n == 0:
            k -= b
            if m > 1:
                b = que_B.popleft()
            m -= 1
        elif a < b:
            k -= a
            if n > 1:
                a = que_A.popleft()
            n -= 1
        else:
            k -= b
            if m > 1:
                b = que_B.popleft()
            m -= 1

    if n == m and n == 0:
        print(N + M)
    else:
        print(N + M - n - m - 1)


if __name__ == '__main__':
    N, M, K = list(map(int, input().split()))
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    main(N, M, K, A, B)

Submission status: Wrong Answer

Solution code:
def resolve():
    '''
    code here
    '''

    N, M, K = [int(item) for item in input().split()]
    As = [int(item) for item in input().split()]
    Bs = [int(item) for item in input().split()]

    res = 0
    time = 0
    while time <= K:
        if not As and not Bs:
            break
        elif not As:
            time += Bs[0]
            del Bs[0]
            res +=1
        elif not Bs:
            time += As[0]
            del As[0]
            res += 1
        else:
            a = As[0]
            b = Bs[0]

            if a <= b and As:
                time += As[0]
                del As[0]
            elif Bs:
                time += b
                del Bs[0]
            res += 1  
        # print(res, time)
        # print(As)
        # print(Bs)

    if time > K:
        print(res -1)
    else:
        print(res)

if __name__ == "__main__":
    resolve()

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()))
t = 0
c = 0
if sum(a) + sum(b) <= k:
    print(n+m)
    quit()
for i in range(min(n, m)):
    if t + a[i]> k:
        break
    t += a[i]
    c += 1
    if t + b[i]> k:
        break
    t += b[i]
    c += 1
if t < k:
    for i in range (min(n, m)-1, max(n, m)-1):
        if max(n, m) == n:
            if t + a[i] > k:
                break
            else:
                t += a[i]
                c += 1
        else:
            if t + b[i] > k:
                break
            else:
                t += b[i]
                c += 1
    print(c)
else:
    print(c)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
data = list(map(int,input().split()))
numOfBooksA=data[0]
numOfBooksB=data[1]
time=data[2]

nextA=0
nextB=0
count=0
overAflg=0
overBflg=0

booksA=list(map(int,input().split()))
booksB=list(map(int,input().split()))

for i in range(numOfBooksA+numOfBooksB+1):
    if(time < 0):
        count = count - 1
        break
    if(time==0):
        break
    
    if(overAflg==1 and overBflg==0):
        time = time - booksB[nextB]
        nextB = nextB + 1
        if (len(booksB) == nextB):
            overBflg=1
        count = count + 1
        continue
        
    if(overAflg==0 and overBflg==1):
        time = time - booksA[nextA]
        nextA = nextA + 1
        if (len(booksA) == nextA):
            overAflg=1
        count = count + 1
        continue

    if (booksA[nextA] <= booksB[nextB]):
        time = time - booksA[nextA]
        nextA = nextA + 1
        if (len(booksA) == nextA):
            overAflg=1
        count = count + 1
        continue
    
    if (booksA[nextA] > booksB[nextB]):
        time = time - booksB[nextB]
        nextB = nextB + 1
        if (len(booksB) == nextB):
            overBflg=1
        count = count + 1
        continue

print(count)

Submission status: Wrong Answer

Solution code:
import bisect
import numpy

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

cost_a = numpy.insert(numpy.cumsum(a), 0, 0)
cost_b = numpy.insert(numpy.cumsum(b), 0, 0)

left_max = bisect.bisect_left(cost_a, k)
right_max = bisect.bisect_left(cost_b, k)

ans = 0
for i in range(left_max):
    for j in range(right_max):
        if cost_a[i] + cost_b[j] <= k:
            ans  = i + j if ans < i + j else ans
        else:
            break
print(ans)

Submission status: Wrong Answer

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

t = 0
ans = 0
while True:
    # aにもbにも本がない場合ブレーク
    if not a and not b:
        break
    # aに本がなく、bに本がある場合はbからpop
    if not a and b:
        x = b.popleft()
    # その逆
    elif not b and a:
        x = a.popleft()
    # どちらにも本がある場合
    elif a and b:
        if a[0] <= b[0]:
            x = a.popleft()
        else:
            x = b.popleft()
    

    if t + x > k:
        break
    else:
        t += x
        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()))
gok=0
ans=0
i=0
j=0
while i<n and j<m:
    if a[i]<=b[j]:
        if gok+a[i]<=k:
            gok+=a[i]
            i+=1
            ans+=1
        else:
            print(ans)
            exit()
    else:
        if gok+b[j]<=k:
            gok+=b[j]
            j+=1
            ans+=1
        else:
            print(ans)
            exit()
            
while i==n and j<m:
    if gok+b[j]<=k:
        gok+=b[j]
        j+=1
        ans+=1
    else:
        print(ans)
        exit()    
            
while j==m and i<n:
    if gok+a[i]<=k:
        gok+=a[i]
        i+=1
        ans+=1
    else:
        print(ans)
        exit()    
            
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque


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

    ans = 0
    tmp = 0
    A_d = deque()
    A_d.append(0)
    B_d = deque()
    B_d.append(0)
    for a in A:
        if tmp + a > K:
            break
        tmp += a
        A_d.append(A_d[-1]+a)
    tmp = 0
    for b in B:
        if tmp + b > K:
            break
        tmp += b
        B_d.append(B_d[-1]+b)
    A_d.popleft()
    B_d.popleft()

    tmp = len(A_d)
    for i, b in enumerate(B_d, 1):
        if A_d[-1] + b > K:
            break
        tmp += 1
    ans = tmp
    tmp = len(B_d)
    for i, a in enumerate(A_d, 1):
        if B_d[-1] + a > K:
            break
        tmp += 1
    print(max(ans, tmp))


if __name__ == "__main__":
    main()

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()))
books = 0
timer = 0
#全部読む必要があるなら全部読んで終わる
if sum(A) + sum(B) <= K:
    print(len(A)+len(B))
#入力例３対策
elif min(A) > K and min(B) > K:
    print(0)
else:
    for i in range(len(A)+len(B)):
        if len(A) == 0 and len(B) != 0:
            books += 1
            timer += B[0]
            if timer > K:break
            B = B[1:]
        elif len(A) != 0 and len(B) == 0:
            books += 1
            timer += A[0]
            if timer > K:break
            A = A[1:]
        elif  A[0] > B[0]:
            books += 1
            timer += B[0]
            if timer > K:break
            B = B[1:]
        elif B[0] > A[0]:
            books += 1
            timer += A[0]
            if timer > K:break
            A = A[1:]
        else:
            #A[0]=B[0]
            tmp = A[0]
            books += 1
            timer += A[0]
            if timer > K:break
            books += 1
            timer += B[0]
            if timer > K:break
            A = A[1:]
            B = B[1:]
    print(books-1)

Submission status: Wrong Answer

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

p_time = 0
time = 0
while time <= k:
    if len(a) > 0 and len(b) > 0:
        if a[0] <= b[0]:
            time += a[0]
            a.remove(a[0])
        else:
            time += b[0]
            b.remove(b[0])
    elif len(a) <= 0 and len(b) <= 0:
        break
    elif len(a) <= 0 < len(b):
        time += b[0]
        b.remove(b[0])
    elif len(b) <= 0 < len(a):
        time += a[0]
        a.remove(a[0])
    if time <= k:
        p_time += 1

print(p_time)

Submission status: Wrong Answer

Solution code:
n, m ,k = map(int,input().split())
a_list = [int(a) for a in input().split()]
b_list = [int(b) for b in input().split()]
time = 0
a_num = 0
b_num = 0
count = 0
print(a_list)
print(b_list)

while True:
    
    if (len(a_list) < a_num + 1) and (len(b_list) < b_num + 1): 
        break

    elif  (len(a_list) < a_num + 1) and (len(b_list) >= b_num + 1):
        time += b_list[b_num]      
        b_num += 1
     
    elif (len(a_list) >= a_num + 1) and (len(b_list) < b_num + 1):
        time += a_list[a_num]      
        a_num += 1
        
    elif (len(a_list) >= a_num + 1) and (len(b_list) >= b_num + 1):
        if a_list[a_num] <= b_list[b_num]:
            time += a_list[a_num]
            a_num += 1
        else:
            time += b_list[b_num]      
            b_num += 1
    
    if time <= k:
        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()))
ans = 0
dp = [[-1 for _1 in range(N+1)] for _2 in range(M+1)]
dp[0][0] = 0
for i in range(N):
    dp[0][i+1] = dp[0][i] + A[i]
for j in range(M):
    dp[j+1][0] = dp[j][0] + B[j]
#print(dp)
for m in range(1,M+1):
    for n in range(1,N+1):
        dp[m][n] = dp[m][0] + dp[0][n]
        if dp[m][n] <= K:
            ans = m+n
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
nums=input().split()
#a=int(nums[0])
b=int(nums[1])
n=int(nums[2])
lista=input().split()
listb=input().split()
listb.append(-1)
listall=[]

#acount=0
bcount=0
count=0
time=0
for i in lista:
  anum=int(i)
  for j in range(bcount,b+1):
    bnum=int(listb[j])
    if j==b:
      listall.append(anum)
      break
    if anum<bnum:
      listall.append(anum)
      break
    listall.append(bnum)
    bcount+=1

if bcount!=b:
  for i in range(bcount,b):
    listall.append(int(listb[i]))

for i in listall:
  if i+time>n:
    print(count)
    sys.exit()
  else:
    time+=i
    count+=1
    print(time)
    print(n)
print(count)

Submission status: Wrong Answer

Solution code:

def solve():
    total = 0
    cnt = 0
    while cnt<N+M:
        if A ==[]:
            if total + B[0] <= K:
                cnt += 1
                total+=B[0]
                B.pop(0)
            else:
                print(cnt)
                exit()
        elif B ==[]:
            if total + A[0] <= K:
                cnt += 1
                total+=A[0]
                A.pop(0)
            else:
                print(cnt)
                exit()    
        elif A[0] <= B[0]:
            if total + A[0] <= K:
                cnt += 1
                total+=A[0]
                A.pop(0)
            else:
                print(cnt)
                exit()
        else:
            if total + B[0] <= K:
                cnt += 1
                total+=B[0]
                B.pop(0)
            else:
                print(cnt)
                exit()
#    print(cnt)

if __name__=="__main__":
    N,M,K = list(map(int, input().split()))
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    AB = A+B
    AB.sort()
#    print(AB)
    solve()

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
from bisect import bisect_right

R = lambda: map(int, input().split())
*_, k = R()
a = accumulate(R())
b = list(accumulate(R()))
r = 0
for i, x in enumerate(a, 1):
  if x > k:
    break
  j = bisect_right(b, k - x)
  r = max(r, i + j) 
print(r)