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:
#!/usr/bin/env python3

import sys
from typing import Any, Callable, Deque, Dict, List, Mapping, Optional, Sequence, Set, Tuple, TypeVar, Union
# import time
# import math
# import numpy as np
# import scipy.sparse.csgraph as cs            # csgraph_from_dense(ndarray, null_value=inf), bellman_ford(G, return_predecessors=True), dijkstra, floyd_warshall
# import random                                # random, uniform, randint, randrange, shuffle, sample
# import string                                # ascii_lowercase, ascii_uppercase, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from datetime import date, datetime          # date.today(), date(year,month,day) => date obj; datetime.now(), datetime(year,month,day,hour,second,microsecond) => datetime obj; subtraction => timedelta obj
# from datetime.datetime import strptime       # strptime('2019/01/01 10:05:20', '%Y/%m/%d/ %H:%M:%S') returns datetime obj
# from datetime import timedelta               # td.days, td.seconds, td.microseconds, td.total_seconds(). abs function is also available.
# from copy import copy, deepcopy              # use deepcopy to copy multi-dimentional matrix without reference
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from fractions import Fraction               # Fraction(a, b) => a / b ∈ Q. note: Fraction(0.1) do not returns Fraciton(1, 10). Fraction('0.1') returns Fraction(1, 10)



def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79e+308
    # inf = 2 ** 63 - 1             # (for fast JIT compile in PyPy) 9.22e+18
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def isp():   return input().split()
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    def simulation(k):
        cnt = 0
        while A or B:
            if A and B:
                # print(k)
                if min(A[-1], B[-1]) > k:
                    break
                if A[-1] < B[-1]:
                    k -= A.pop()
                else:
                    k -= B.pop()
                cnt += 1
            elif A:
                if A[-1] > k:
                    break
                k -= A.pop()
                cnt += 1
            else:
                if B[-1] > k:
                    break
                k -= B.pop()
                cnt += 1
        return cnt 

    
    n, m, k = mi()
    A = lmi()
    B = lmi()
    A.reverse()
    B.reverse()

    print(simulation(k))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def read(a,b,k):
    book = 0
    block_a = 0
    block_b = 0
    for i in range(len(a)):
        if k>=a[i]:
            k-=a[i]
            book+=1
        else:
            break
    for i in range(len(b)):
        if k>=b[i]:
            k-=b[i]
            book+=1
        else:
            break
    return book


if __name__ == "__main__":
    n,m,k = map(int,input().split())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    print(read(a,b,k))

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
alis = list(map(int, input().split())) + [1000000]
blis = list(map(int, input().split())) + [1000000]
su = 0
a = 0
b = 0
if sum(alis) + sum(blis) < k:
  print(len(alis) + len(blis))
  quit()
  
while su <= k:
  if alis[a] > blis[b]:
    su += blis[b]
    b += 1
  else:
    su += alis[a]
    a += 1
    
print(a + b - 1)

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 = 0
b = 0
La = len(A)
Lb = len(B)
ans = 0
S = 0
while S <= K:
  if a == N and b == M:
    ans += 1
    break
    
  if a == N:
    va = 10000000000000
  else:
    va = A[a]
    
  if b == M:
    vb = 10000000000000
  else:
    vb = B[b]
    
  if va  < vb:
    a += 1
    S  += va
    ans += 1
  else:
    b += 1
    S += vb
    ans += 1
 
  
print(a+b)

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

T_A = []
T_B = []
for i in range(max(M,N)):
  if i == 0:
    T_A.append(A[0])
    T_B.append(B[0])
  else:
    try:
      T_A.append(T_A[i-1] + A[i])
    except:
      pass
    try:
      T_B.append(T_B[i-1] + B[i])
    except:
      pass

book = 0

for i in range(len(T_A)):
  for j in range(len(T_B)):
    if K < T_A[i] + T_B[j]:
      break
    else:
      if i + j + 2 > book:
        book = i + j + 2
      else:
        pass
    
print(book)

Submission status: Wrong Answer

Solution code:
# import io
# import sys

# _INPUT = """\
# 1 4 730
# 60
# 80 150 80 150
# """
# sys.stdin = io.StringIO(_INPUT)


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


C = [0]
a = b = 0
while True:

  if a >= len(A):
    C += B[b:]
    break

  if b >= len(B):
    C += A[a:]
    break

  if A[a] < B[b]:
    C.append(A[a])
    a += 1
    continue
  else:
    C.append(B[b])
    b += 1
    continue

# print(C)
# 累積和
from itertools import accumulate
#=> [0 1 3 6 10 15]
D = accumulate(C)


for i, d in enumerate(D):
  if d > K: break
  ans = i

print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

ans=0
T=0
for i in range(N):
    T+=A[i]
    if T > K:
        T-=A[i]
        break
    else:
        ans+=1
R=[]
R.append(ans)
n=ans-1
m=0
while(1):
    while(1):
        if m>=M: break
        T+=B[m]
        
        if T > K:
            T-=B[m]
            break
        else:
            ans+=1
            R.append(ans)
            m+=1
            
    n-=1
    if n<0: break
    T-=A[n]
    ans-=1
    

print(max(R))

Submission status: Wrong Answer

Solution code:
# 初期入力
from collections import deque
import sys
input = sys.stdin.readline
N,M,K = (int(i) for i in input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
dq_a =deque(A)
dq_b =deque(B)

#上から読む＝配列の前から読む


read_time =0
ans =0
a=dq_a.popleft()
b=dq_b.popleft()
for i in range(N+M):
    if a <=b and read_time +a <=K:
        read_time +=a
        ans +=1
        if len(dq_a) >0:
            a =dq_a.popleft()
        else:
            a=10**9 +1
    elif a >=b and read_time +b <=K:
        read_time +=b
        ans +=1
        if len(dq_b) >0:
            b =dq_b.popleft()
        else:
            b=10**9 +1
    elif read_time >K:
        break
print(ans)

Submission status: Wrong Answer

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

ans = 0

while True:
    if k <= 0  :
        break
    if len(list_A) == 0 and len(list_B) == 0:
        break

    if len(list_A) == 0:
        k -= list_B[0]
        list_B.pop(0)
    elif len(list_B) == 0:
        k -= list_A[0]
        list_A.pop(0)
    else:
        l = 0
        h = min(len(list_A), len(list_B))
        for i in range(h):
            if list_A[i] > list_B[i]:
                l = 1
                break
            if list_B[i] > list_B[i]:
                l = -1
                break
        if l == 1:
            k -= list_B[i]
            list_B.pop(0)
        elif l == -1:
            k -= list_A[0]
            list_A.pop(0)
        elif l == 0:
            if len(list_A) > len(list_B):
                k -= list_A[0]
                list_A.pop(0)
            elif len(list_B) > len(list_A):
                k -= list_B[0]
                list_B.pop(0)
            else:
                k -= list_A[0]
                list_A.pop(0)
    if k >= 0:
        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()))
t = 0
cnt = 0

while (len(a) > 0 or len(b) > 0) and t <= k:
    if len(a) >= 1 and len(b) >= 1 and a[0] >= b[0]:
        t += b[0]
        if t > k:
            break
        cnt += 1
        del b[0]
        
    elif len(a) >= 1 and len(b) >= 1 and a[0] <= b[0]:
        t += a[0]
        if t > k:
            break
        cnt += 1
        del a[0]
        
    elif len(a) == 0:
        t += b[0]
        if t > k:
            break
        cnt += 1
        del b[0]
        
    elif len(b) == 0:
        t += a[0]
        if t > k:
            break
        cnt += 1
        del a[0]
        

print(cnt)

Submission status: Wrong Answer

Solution code:

n, m, k = map(int, input().split())
from bisect import bisect_right

a = list(map(int, input().split()))
b = list(map(int, input().split()))
total_a = [0] * n
total_b = [0] * m

def set_data(data, a, x):
    data[0] = a[0]
    for i in range(1, x):
        data[i] = data[i - 1] + a[i]

set_data(total_a, a, n)
set_data(total_b, b, m)
ans = 0

for i in range(n - 1, -1, -1):
    if total_a[i] <= k:
        index = bisect_right(total_b, k - total_a[i], 0, m)
        time = total_b[index - 1]
        ans = max(ans, i + index + 1)

print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, M: int, K: int, A: "List[int]", B: "List[int]"):
    cur = sum(A)
    for i in range(N-1,-1,-1):
        if cur>K: cur -= A[i]
        else:break
    if cur==0:
        max_k = 0
        l = 0
    else:
        max_k = i+1
        l = 1
    p = 0
    # print(cur,max_k)
    for q in range(i,-1,-1):
        while(p<M):
            if cur+B[p] <= K:
                cur+=B[p]
                max_k = max(q+l+p+1, max_k)
                p+=1
            else:
                break
        cur -= A[q]
    print(max_k)





    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    B = [int(next(tokens)) for _ in range(M)]  # type: "List[int]"
    solve(N, M, K, A, B)

if __name__ == '__main__':
    main()

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())))
k = 0

for n in range(N+M):
    if not A and not B:
        break
    elif not A:
        K = K - B.popleft()
    elif not B:
        K = K - A.popleft()
    elif A[0] <= B[0]:
        K = K - A.popleft()
    elif B[0] < A[0]:
        K = K - B.popleft()

    if K >= 0:
        k = k + 1
    else:
        break

print(k)

Submission status: Wrong Answer

Solution code:
import bisect
n, m, lim = map(int, input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
s = [0] * (n+m+1)
nowt = 0
acnt = 0
bcnt = 0

a.append(10**9+1)
b.append(10**9+1)
for i in range(1, n+m+1):
  if a[acnt] < b[bcnt]:
    s[i] = s[i-1] + a[acnt]
    acnt += 1
  else:
    s[i] = s[i-1] + b[bcnt]
    bcnt += 1

print(bisect.bisect_right(s, lim)-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()))
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:
    if n == m:
        print(c)
    else:
        for i in range (min(n, m)-1, max(n, m)):
            if max(n, m) == n:
                if t + a[i] > t:
                    break
                else:
                    t += a[i]
                    c += 1
            else:
                if t + b[i] > t:
                    break
                else:
                    t += b[i]
                    c += 1
        print(c)
else:
    print(c)

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

C = deque()


while len(A) > 0 and len(B) > 0:
  if A[0] >= B[0]:
    C.append(B[0])
    B.popleft()
  else:
    C.append(A[0])
    A.popleft()

while len(A) > 0:
  C.append(A[0])
  A.popleft()
  
while len(B) > 0:
  C.append(B[0])
  B.popleft()

time = 0
count = 0
for c in C:
  if c + time < K:
    count += 1
    time += c
  else:
    break

print(count)

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

time = 0
cnt = 0

while time <= K:
    if len(A) == 0 and len(B) == 0:
        break
    elif len(A) == 0:
        if B[0]+time <= K:
            time += B[0]
            cnt += 1
            B.popleft()
        else:
            break
    elif len(B) == 0:
        if A[0]+time <= K:
            time += A[0]
            cnt += 1
            A.popleft()
        else:
            break
    else:
        if B[0]+time <= K or A[0]+time <= K:
            if A[0] <= B[0]:
                time += A[0]
                cnt += 1
                A.popleft()
            else:
                time += B[0]
                cnt += 1
                B.popleft()
        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()))
ai = 0
bi = 0
ans = 0
cur = 0
for _ in range(n+m):
    if ai < n and bi < m:
        if a[ai] < b[bi]:
            cur += a[ai]
            ai += 1
        else:
            cur += b[bi]
            bi += 1
    elif ai < n:
        cur += a[ai]
        ai += 1
    elif bi < m:
        cur += b[bi]
        bi += 1
    else:
        break
    
    if cur > k:
        break
    else:
        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()))
cost = 0
ans = 0
pa = 0
pb = 0
while True:
	if pa < N and pb < M:
		if A[pa] < B[pb]:
			cost += A[pa]
			if cost > K:
				break;
			ans += 1
			pa += 1
		elif A[pa] > B[pb]:
			cost += B[pb]
			if cost > K:
				break;
			ans += 1
			pb += 1
		else:
			l = pa
			k = pb
			while A[l] == B[k]:
				l += 1
				k += 1
				if l == N or k == M:
					l -= 1
					k -= 1
					break;
			if A[l] < B[k]:
				cost += A[pa]
				if cost > K:
					break;
				ans += 1
				pa += 1
			else:
				cost += B[pb]
				if cost > K:
					break;
				ans += 1
				pb += 1		
	if pa < N and pb >= M:
		cost += A[pa]
		if cost > K:
			break;
		ans += 1
		pa += 1
	if pa >= N and pb < M:
		cost += B[pb]
		if cost > K:
			break;
		ans += 1
		pb += 1
	if pa >= N and pb >= M:
		break;
print(ans)

Submission status: Wrong Answer

Solution code:
M, N, K = map(int, input().split())
A = map(int,input().split())
B = map(int,input().split())
C, H, N = list(A) + list(B), 0, 0
if min(C) < K:
  while H < K:
    min_hour = min(C)
    H += min_hour
    N += 1
    C.remove(min_hour)
print(N)

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()]
i,j=0,0

t=0
if k>=sum(a) + sum(b):
    print(n+m)
else:
    while(t<k):
        if i==n and j<m:

            t+=b[j]
            j+=1
        elif j==m and i<n:

            t+=a[i]
            i+=1
        else:
            if a[i]<b[j]:

                t+=a[i]
                i+=1
            else:

                t+=b[j]
                j+=1
        #print(i,j,t)
    if t>k:
        print(i+j-1)
    else:
        print(i+j)

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
for i in range(N+M):
    if a[0]<b[0]:
        K-=a[0]
        ans+=1
        a.pop(0)
    else:
        K-=b[0]
        ans+=1
        b.pop(0)
    if K<=0:
        flag=0
        break
    if len(a)==0:
        flag=1
        break
    if len(b)==0:
        flag=2
        break
if flag==1:
    for x in b:
        K-=x
        ans+=1
        if K<=0:
            flag=0
            break
elif flag==2:
    for x in a:
        K-=x
        ans+=1
        if K<=0:
            flag=0
            break

if K>=0:
    print(ans)
else:
    print(ans-1)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
@author: H_Hoshigi
"""
import bisect

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

    A_sum_list = [0] + A_lsit[:]
    for i in range(1, N+1):
        A_sum_list[i] = A_sum_list[i-1] + A_lsit[i-1]
    B_sum_list = [0] + B_lsit[:]
    for i in range(1, M+1):
        B_sum_list[i] = B_sum_list[i-1] + B_lsit[i-1]
    #print(A_sum_list)
    #print(B_sum_list)

    max_book_number = 0
    for i in range(N):
        book_number_A = i
        book_number_B = bisect.bisect_right(B_sum_list, K-A_sum_list[i]) - 1
        max_book_number = max(
            max_book_number,
            book_number_A + book_number_B
        )
        #print(book_number_A, book_number_B, book_number_A + book_number_B)
    print(max_book_number)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
sa=[0]*(n+1)
sb=[0]*(m+1)
for i in range(1,n+1):
    sa[i]=sa[i-1]+a[i-1]
for j in range(1,m+1):
    sb[j]=sb[j-1]+b[j-1]
ans=0
for x in range(n+1):
    if k-sa[x]>0:
        k2=k-sa[x]
        l=bisect_right(sb,k2)-1
        if x+l>ans:
            ans=x+l
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque

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

qa = deque(A)
qb = deque(B)

MAX = float("INF")

ans, t = 0, 0
while True:
    if len(qa) == 0 and len(qb) != 0:
        a = MAX; b = qb.popleft()
    elif len(qa) != 0 and len(qb) == 0:
        a = qa.popleft(); b = MAX
    elif len(qa) == 0 and len(qb) == 0:
        break
    else:
        a = qa.popleft(); b = qb.popleft()
        
    if a < b:
        t += a
        if len(qb) != 0:
            qb.appendleft(b)
    else:
        t += b
        if len(qa) != 0:
            qa.appendleft(a)
        
    if t <= K:
        ans += 1
    else:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate

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

acc1 = list(accumulate(A))
acc2 = list(accumulate(B))

def s():
    ans = 0
    j = 0
    for i in reversed(range(N)):
        temp = 0
        while(1):
            if j == M:
                ans = i + j + 1
                return ans
            c = acc1[i] + acc2[j]
            if c <= K:
                temp = i + j + 2
                j += 1
            else:
                if temp == 0:
                    if acc1[i] <= K:  temp = 1
                j = 0
                ans = max(ans, temp)
                break
    return ans

print(s())

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()))
    ai, bi = 0, 0
    time = 0
    ans = 0
    book = 0
    while time <= K:
        if ai == N and bi == M:
            print(ans)
        elif ai == N and bi < M:
            book = B[bi]
            bi += 1
        elif ai < N and bi == M:
            book = A[ai]
            ai += 1
        else:
            if A[ai] <= B[bi]:
                book = A[ai]
                ai += 1
            else:
                book = B[bi]
                bi += 1
        if time + book < K:
            ans += 1
            time += book
        elif time + book == K:
            ans += 1
            break
        else:
            break
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
a,b,k = map(int, input().split())
arr1 = list(map(int, input().split()))
arr2 = list(map(int, input().split()))
i = 0
j = 0
c = 0
if k < min(arr1[0], arr2[0]):
	print(0)
	exit()
while i < a or j < b:
	if i == a:
		if j < b and k >= arr2[j]:
			k -= arr2[j]
			j += 1
		else:
			break
	elif j == b:
		if i < a and k >= arr1[i]:
			k -= arr1[i]
			i += 1
		else:
			break
	elif arr1[i] < arr2[j] and k >= arr1[i]:
		k -= arr1[i]
		i += 1
	elif arr2[j] <= arr1[i] and k >= arr2[j]:
		k -= arr2[j]
		j += 1
	c += 1
print(c)

Submission status: Wrong Answer

Solution code:

def main():
    N_A, M_B, K = map(int, input().split())

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

    ans = 0
    summ = 0
    index_a = 0
    index_b = 0
    
    

    for i in range(N_A + M_B):
        if (index_a + 1 > N_A):

            nextt = B[index_b]
            index_b += 1
        elif (index_b + 1 > M_B):
            nextt = A[index_a]
            index_a += 1
        else:
            if (A[index_a] >= B[index_b]):
                nextt = B[index_b]
                index_b += 1
            else:
                nextt = A[index_a]
                index_a += 1
                
        summ += nextt
        
        
        
        if (summ <= K):
            ans += 1
        else:
            break



    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()))
a = A[0]
if A[0]<= K:
    max = 1
else:
    max = 0
for i in range(1,N):
    a += A[i]
    A[i] = a
    if a <= K:
        max = i+1
b = B[0]
if max >= 1:
    L = K-A[max-1]
else:
    L = K
if B[0]<= L:
    m = 1
else:
    m = 0
for i in range(1,M):
    b += B[i]
    B[i] = b
    if b <= L:
        m = i+1
ans = max+m
if max ==0 and m == 0:
    print(0)
else:
    while(max > 0 and m<M):
        max -= 1
        L = K-A[max-1]
        while(m<M and B[m]<=L):
                m += 1
        if max + m > ans:
            ans = max+m
    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()))

def doku(li, K, time):
  cnt = 0
  tmp = 0
  for i in range(len(li)):
    if time+li[i] <= K:
      tmp += li[i]
      cnt += 1
    else:
      return cnt
  return cnt

ans = 0
time = 0
while time+min(A[0], B[0]) <= K:
  plus = min(A[0], B[0])
  time += plus
  ans += 1
  if A[0] <= B[0]:
    A.pop(0)
    if not A:
      ans += doku(B, K, time)
      break;
  else:
    B.pop(0)
    if not B:
      ans += doku(A, K, time)
      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()))
SUM_A=[0 for _ in range(N+1)]
for i in range(N):
    SUM_A[i+1] = A[i] + SUM_A[i]
    if SUM_A[i+1] > K:
        N=i
        break

SUM_B=[0 for _ in range(M+1)]
for i in range(M):
    SUM_B[i+1] = B[i] + SUM_B[i]
    if SUM_B[i+1] > K:
        M=i
        break

print(N,M)
cnt = 0
for i in range(N+1):
    for j in range(M+1):
        if SUM_A[i]+SUM_B[j] <= K:
            if i+j > cnt:
                cnt = i+j
        else:
            break
print(cnt)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
import bisect
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
aa=list(accumulate(a))
b=list(map(int,input().split()))
bb=list(accumulate(b))
ans=0
for i in range(n):
    if aa[i]>k:
        break
    tmp=k-aa[i]
    t=bisect.bisect(bb,tmp)
    if i+1+t>ans:
        ans=i+t+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()))
time = 0
count = -1
for i in range(200000 * 2):
  if time > k:
    break
  try:
    if a[0] == b[0]:
      if a[1] < b[1]:
        top = a.pop(0)
      else:
        top = b.pop(0)
    elif a[0] < b[0]:
      top = a.pop(0)
    else:
      top = b.pop(0)
  except IndexError:
    if a:
      top = a.pop(0)
    elif b:
      top = b.pop(0)
    else:
      count += 1
      break
  time += top
  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()))
i=j=0
ans=0
while i<n and j<m and k>0 and (k>=a[i] or k>=b[j]):
  if(a[i]<=b[j]):
    k-=a[i]
    i+=1
  else:
    k-=b[j]
    j+=1
  ans+=1
while k>0 and i<n and k>=a[i]:
  k-=a[i]
  i+=1
  ans+=1
while k>0 and j<m and k>=b[j]:
  k-=b[j]
  j+=1
  ans+=1
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()))

count = 0

n = N + M

S = A + B
S = np.sort(S)

for i in range(n):
    if S[i] <= K:
        K = K - S[i]
        count += 1
    else:
        break

print(count)

Submission status: Wrong Answer

Solution code:
import collections

n,m,k = map(int,input().split())
a = collections.deque()
A = list(map(int,input().split()))
for i in A:
    a.append(i)
b = collections.deque()
B = list(map(int,input().split()))
for i in B:
    b.append(i)

ans = 0
time = 0
while time < k:
    if len(a) != 0 and len(b) != 0:
        if a[0] < b[0]:
            ans += 1
            tmp = a.popleft()
            time += tmp        
        elif a[0] > b[0]:
            ans += 1
            tmp = b.popleft()
            time += tmp       
        elif a[0] == b[0]:
            for i in range(1,min(len(a),len(b))):
                if a[i] < b[i]:
                    ans += 1
                    tmp = a.popleft()
                    time += tmp
                    break
                elif a[i] > b[i]:
                    ans += 1
                    tmp = b.popleft()
                    time += tmp
                    break
                else:
                    pass
            else:
                if len(a) == len(b):
                    ans += 1
                    tmp = a.popleft()
                    time += tmp
                elif len(a) > len(b):
                    ans += 1
                    tmp = a.popleft()
                    time += tmp
                elif len(a) < len(b):
                    ans += 1
                    tmp = b.popleft()
                    time += tmp
    elif len(a) == 0 and len(b) != 0:
        ans += 1
        tmp = b.popleft()
        time += tmp
    elif len(b) == 0 and len(a) != 0:
        ans += 1
        tmp = a.popleft()
        time += tmp
    else:
        break        
    if time > k:
        ans -= 1
        break

print(ans)