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


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
    else: max_k = i+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+1+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:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
for s in range(abs(n-m)):
	if n>m:
		b.append(0)
	elif m>n:
		a.append(0)
ans=0
total=0
for i,j in zip(a,b):
	if i==0 or j==0:
		total+=max(i,j)
		if total<=k:
			ans+=1
			continue
		else:
			break
	total+=min(i,j)
	if total<=k:
		ans+=1
		total+=max(i,j)
		if total<=k:
			ans+=1
		else:
			break
	else:
		break
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
input1 = list(map(int, input().split()))
N = input1[0]
M = input1[1]
K = input1[2]

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

num_a = 0
num_b = 0

book_count = 0
time_count = 0

flag_a = True
flag_b = True

tmp = 0

while(time_count < K):
    if(flag_a and flag_b):
        if(A[0] <= B[0] ):
            tmp = A.pop(0)
            time_count += tmp
            book_count += 1
            # print("type1", tmp)
            if(len(A) == 0):
                flag_a = False
        else:
            tmp = B.pop(0)
            time_count += tmp
            book_count += 1
            # print("type2", tmp)
            if(len(B) == 0):
                flag_b = False

    elif(flag_a and not flag_b):
        tmp = A.pop(0)
        time_count += tmp
        book_count += 1
        # print("type3", tmp)
        if(len(A) == 0):
            flag_a = False
    
    elif(not flag_a and flag_b):
        tmp = B.pop(0)
        time_count += tmp
        book_count += 1
        # print("type4", tmp)
        if(len(B) == 0):
            flag_b = False
        
    else:
        book_count += 1
        # print("type5", tmp)
        break


print(book_count - 1 if time_count > K else 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()))
AB = A + B
AB.sort()
x = 0

for i in range(N + M):
    if AB[i] <= K:
        x = x + 1
        K = K - AB[i]

print(x)

Submission status: Wrong Answer

Solution code:
x = input().split()
y = input().split()
z = input().split()
s = 0
for nn in range(2000000):
    y.append(10000000001)
    z.append(10000000001)
for nn in range(2000000):
    if int(x[2]) < 0:
        break
    if int(y[0]) <= int(z[0]) :
        x[2] = int(x[2]) - int(y[0])
        del y[0]   
        s += 1
    else:
        x[2] = int(x[2]) - int(z[0])
        del z[0]
        s += 1
print(s-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()))

cumsum=0
cnt=0
i=0
j=0
while True:
    if i>n-1:
        a_i=10**9 + 1
    else:
        a_i=a[i]

    if j>m-1:
        a_i=10**9 + 1
    else: 
        b_i=b[j]   

    if a_i<=b_i:
        cumsum+=a_i
        i+=1
    else:
        cumsum+=b_i
        j+=1

    if cumsum<=k:   
        cnt+=1
    else:
        break
    
    #本をすべてとった
    if i>n-1 and j>m-1:
        cnt=n+m
        break
    
print(cnt)

Submission status: Wrong Answer

Solution code:
from sys import stdin

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

index_A = 0
index_B = 0
now = 0
count = 0

while True:
    if A[index_A] >= B[index_B]:
        now += B[index_B]
        index_B += 1
        count += 1
    else:
        now += A[index_A]
        index_A += 1
        count += 1
    if now > K:
        count -= 1
        break
    if index_A > len(A)-1 or index_B > len(B)-1:
        break

if index_A > len(A)-1:
    while True:
        if now+B[index_B] <= K:
            now += B[index_B]
            count += 1
            index_B += 1
            if index_B > len(B)-1:
                break
        else:
            break
else:
    while True:
        if now + A[index_A] <= K:
            now += A[index_A]
            count += 1
            index_A += 1
            if index_A > len(A)-1:
                break
        else:
            break
print(count)

Submission status: Wrong Answer

Solution code:
import numpy as np
def main():
    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    
    cost = 0
    count = 0
    while True:
        if len(A) ==0 and len(B) == 0:
            break
        a = A[0] if len(A) > 0 else 10**9
        b = B[0] if len(B) > 0 else 10**9
        if a < b:
            if a + cost > K:
                break
            cost += a
            A = A[1:]
        else:
            if b + cost > K:
                break
            cost += b
            B = B[1:]

        count += 1
    
    print(count)


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

Submission status: Wrong Answer

Solution code:
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_list(N): return [s_list() for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def main():
    n, m, k = i_map()
    a_list = i_list()
    b_list = i_list()

    a_deque = deque(a_list)
    b_deque = deque(b_list)

    read_time = 0

    for i in range(n+m):
        if read_time > k:
            print(i-1)
            exit()
        if read_time == k:
            print(i)
            exit()

        if len(a_deque) == 0:
            a = INF
        else:
            a = a_deque.popleft()
        if len(b_deque) == 0:
            b = INF
        else:
            b = b_deque.popleft()

        if a <= b:
            read_time += a
            b_deque.appendleft(b)
            # print(i,read_time)
        else:
            read_time += b
            a_deque.appendleft(a)
            # print(i,read_time)

    print(n+m)
 
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
A, B, K = map(int, input().split())
Ai = list(map(int, input().split()))
Bi = list(map(int, input().split()))
result = 0
count = 0
Ai.extend(Bi)
Ai.sort()
for i in range(len(Ai)):
    result += Ai[i]
    if K < result:
        print(count)
        exit()
    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_index = 0
b_index = 0

ans = 0

while 0 <= k:
    if a_index >= len(a) and b_index >= len(b):
        ans += 1
        break
    elif a_index >= len(a):
        k -= b[b_index]
        b_index += 1
        ans += 1
        continue
    elif b_index >= len(b):
        k -= a[a_index]
        a_index += 1
        ans += 1
        continue

    if a[a_index] <= b[b_index]:
        k -= a[a_index]
        a_index += 1
        ans += 1
    else:
        k -= b[b_index]
        b_index += 1
        ans += 1

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

init = 0
init2 = 0
s = 0
for i in range(n):
  if s + a[i] <= k:
    s += a[i]
    init += 1

k2 = k - s
for i in range(m):
  if s + b[i] <= k:
    s += b[i]
    init2 += 1

max_ = init+init2
while init > 0:
  s -= a[init-1]
  init -= 1
  for i in range(init2, m):
    if s + b[i] <= k:
      s += b[i]
      init2 += 1
    else:
      break
  max_ = max(max_, init+init2)
print(max_)

Submission status: Wrong Answer

Solution code:
N,M,K=map(int,input().split())
a=input().split()
A=[int(c) for c in a]
b=input().split()
B=[int(c) for c in b]
answer=0
numbers=[]
a=0
b=0
while a<N and b<M:
    if A[a]>=B[b]:
        numbers.append(B[b])
        b+=1
    else:
        numbers.append(A[a])
        a+=1

if a<N:
    for a in A[a:]:
        numbers.append(a)
else:
    for b in B[b:]:
        numbers.append(b)
whole=0
for a in range(N+M):
    whole+=numbers[a]
    if whole<K:
        answer+=1
print(answer)

Submission status: Wrong Answer

Solution code:
from collections import deque
N, M, K = map(int, input().split())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
if sum(A) + sum(B) <= K:
    print(len(A)+len(B))
else:
    A = deque(A)
    B = deque(B)
    time = 0
    ans = 0
    while time < K:
        if len(A) == 0:
            time += B[0]
            ans += 1
            B.popleft()
        elif len(B) == 0:
            time += A[0]
            ans += 1
            A.popleft()
        else:
            if A[0] <= B[0]:
                time += A[0]
                ans += 1
                A.popleft()
            else:
                time += B[0]
                ans += 1
                B.popleft()
    print(ans-1)

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

a = A.popleft()
b = B.popleft()
ans = 0

while k > 0:
    if a <= b:
        k -= a
        if len(A) == 0:
            a = float('inf')
        else:
            a = A.popleft()
    else:
        k -= b
        if len(B) == 0:
            b = float('inf')
        else:
            b = B.popleft()
    if k >= 0:
        ans += 1
    else:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque

n,m,k = map(int,input().split())
li_a = deque(list(map(int,input().split())))
li_b = deque(list(map(int,input().split())))
ans,cnt = 0,0

for i in range(n+m):
    if n == 0:
        for i in li_b:
            if cnt + i > k:
                break
            else:
                cnt += i
                ans += 1
    elif m == 0:
        for j in li_a:
            if cnt + j > k:
                break
            else:
                cnt += j
                ans += 1
    elif li_a[0] <= li_b[0]:
        temp = li_a.popleft()
        n -= 1
    else:
        temp = li_b.popleft()
        m -= 1

    if cnt + temp > k:
        break
    else:
        cnt += temp
        ans += 1

print(ans)

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()))
    a.append(10**9)
    b.append(10**9)
    a, b = a[::-1], b[::-1]
    sum = 0
    for _ in range(200000):
        if a[-1] <= b[-1]:
            k -= a.pop()
        else:
            k -= b.pop()

        if k < 0:
            break
        sum += 1
    print(sum)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import deque

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

count = 0
time = 0

for i in range(N+M):
    if len(A) > 1 and len(B) > 1:
        if A[0] > B[0]:
            time += B.popleft()
        else:
            time += A.popleft()
    elif len(A) > 1:
        time += A.popleft()
    elif len(B) > 1:
        time += B.popleft()
    count += 1
        
    if time > K:
        count -= 1
        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()))
r=0
t=0
m_i=0
n_i=0
m+=-1
n+=-1
for i in range(m+n+2):
  #print(n_i)
  a_i=a[min(n_i,n)]
  b_i=b[min(m_i,m)]
  if ((a_i>b_i and m_i <=m) or (n_i > n)):
    m_i+=1
    t+=b_i
    #m_i=min(m_i,m)
  else:
    n_i+=1
    t+=a_i
    #n_i=min(n_i,n)
  if t>k:
    break
  r+=1
print(r)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(2 * 10**6)


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


def main():
    N, M, K = inpl()
    A = inpl()
    B = inpl()
    a, b = 0, 0
    while True:
        if a == N and b == M:
            break
        elif a == N:
            if B[b] > K:
                break
            else:
                K -= B[b]
                b += 1
        elif b == len(B):
            if A[a] > K:
                break
            else:
                K -= A[a]
                a += 1
        elif A[a] > K and B[b] > K:
            break
        elif A[a] <= B[b]:
            K -= A[a]
            a += 1
        elif B[b] < A[a]:
            K -= B[b]
            b += 1

    print(a + b)

    return


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
deta = list(input().split(" "))
ahon = int(deta[0])
bhon = int(deta[1])
time = int(deta[2])

alist = list(input().split(" "))
blist = list(input().split(" "))

book = 0
while time > 0:
    if alist == [] and blist == []:
        break
    elif alist == []:
        if int(blist[0]) > time:
            break
        else:
            time -= int(blist[0])
            book += 1
            blist.pop(0)
    elif blist == []:
        if int(alist[0]) > time:
            break
        else:
            time -= int(alist[0])
            book += 1
            alist.pop(0)
    elif int(alist[0]) <= int(blist[0]):
        if int(alist[0]) > time:
            break
        else:
            time -= int(alist[0])
            book += 1
            alist.pop(0)
    elif int(alist[0]) > int(blist[0]):
        if int(blist[0]) > time:
            break
        else:
            time -= int(blist[0])
            book += 1
            blist.pop(0)

print(book)

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()))
t = 0
c = 0
while True:
    if len(a) == 0 and len(b) == 0:
        break
    if len(a) == 0:
        t += b.popleft()
    elif len(b) == 0:
        t += a.popleft()
    else:
        if a[0] >= b[0]:
            t += b.popleft()
        else:
            t += a.popleft()
    if t > k:
        break
    c += 1
print(c)

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 ms(a, b, r, n, m): 
    i, j, k = 0, 0, 0
    while (i < n): 
        res[k] = a[i] 
        i += 1
        k += 1
    while (j < m): 
        res[k] = b[j] 
        j += 1
        k += 1
    res.sort() 
res = [0 for _ in range(n+m)]
ms(a, b, res, n, m)
c = 0
f = 0
for i in range(len(res)):
    if c+res[i]<=k:
        f+=1
        k-=c+res[i]
print(f)

Submission status: Wrong Answer

Solution code:
n,m,k=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]+[10**9]
b=[int(i) for i in input().split()]+[10**9]
r=0
c=0
ai=0
bi=0
while True:
    if a[ai:] < b[bi:]:
        _r=a[ai]
        ai+=1
    else:
        _r=b[bi]
        bi+=1
    if r+_r <= k:
        r+=_r
        c+=1
    else:
        break
print(c)

Submission status: Wrong Answer

Solution code:
def main(n, m, k, a_n, b_n):
    r = 0

    for _ in range(n+m):
        if len(a_n) > 0:
            a_v = a_n[0]
        else:
            a_v = float('inf')

        if len(b_n) > 0:
            b_v = b_n[0]
        else:
            b_v = float('inf')

        if a_v == float('inf') and b_v == float('inf'):
            return r

        if a_v < b_v:
            k -= a_n.pop(0)
        else:
            k -= b_n.pop(0)

        if k >= 0:
            r += 1

        if k <= 0:
            return r
    return r

if __name__ == "__main__":
    n, m, k = map(int, input().split())
    a_n = [int(x) for x in input().split()]
    b_n = [int(x) for x in input().split()]
    print(main(n, m, k, a_n, b_n))

Submission status: Wrong Answer

Solution code:
import sys
n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

count = 0
time = 0
a = 0
b = 0
while time <= k:
    if a == n:
        if b == m:
            print(n + m)
            sys.exit()
        else:
            time += B[b]
            b += 1
            count += 1
    elif b == m:
        time += A[a]
        a += 1
        count += 1
    elif A[a] <= B[b]:
        time += A[a]
        a += 1
        count += 1
    else:
        time += B[b]
        b += 1
        count += 1
    # print(count, time)
    if time == k:
        print(count)
        sys.exit()
    
print(count-1)

Submission status: Wrong Answer

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

ia = 0
ib = 0
t = 0

ic = 0
cc = [0] * (n + m)
while True:
    if ia >= n and ib >= m:
        break
    if ia >= n:
        cc[ic] = bb[ib]
        ic += 1
        ib += 1
    elif ib >= m:
        cc[ic] = aa[ia]
        ic += 1
        ia += 1
    else:
        if aa[ia] < bb[ib]:
            cc[ic] = aa[ia]
            ic += 1
            ia += 1
        else:
            cc[ic] = bb[ib]
            ic += 1
            ib += 1

t = 0
for i in range(n + m):
    if t + cc[i] > k:
        print(i)
        exit(0)
    t += cc[i]
print(n + m)

Submission status: Wrong Answer

Solution code:
import bisect
from itertools import accumulate

n, m, k = map(int, input().split())
a = tuple(accumulate(map(int, input().split())))
b = tuple(accumulate(map(int, input().split())))
s = 0

cnt = 0
for i, j in enumerate(a):
    if j <= k:
        cnt = max(cnt, i + bisect.bisect_right(b, k - j) + 1)
print(cnt)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import sys

l = stdin.readline().rstrip().split(' ')
a = stdin.readline().rstrip().split(' ')
b = stdin.readline().rstrip().split(' ')
k = int(l[2])
n = int(l[0])
m = int(l[1])
ia = 0
ib = 0
sum = 0
count = 0
for num in range(n+m):
    if ia < n and ib < m:
        if int(a[ia]) < int(b[ib]):
            sum += int(a[ia])
            ia += 1
        else:
            sum += int(b[ib])
            ib += 1
    elif ia < n:
        sum += int(a[ia])
        ia += 1
    elif ib < m:
        sum += int(b[ib])
        ib += 1
    #print("sum:" + str(sum))
    if sum <= k:
        count += 1
    else:
        break
print(count)

Submission status: Wrong Answer

Solution code:
N, M, K = [int(i) for i in input().split()]
A = [10**18] + [int(i) for i in input().split()][::-1]
B = [10**18] + [int(i) for i in input().split()][::-1]

t = 0
c = 0
while True:
    if t > K: break
    a = A[-1]
    b = B[-1]
    if min(a, b) == 10**18: break

    if a <= b:
        if t + a <= K:
            t += A.pop()
            c += 1
        else: break
    else:
        if t + b <= K:
            t += B.pop()
            c += 1
        else: break

print(c)

Submission status: Wrong Answer

Solution code:

def main():
    n, m, k = map(int, input().split())
    aa = list(map(int, input().split()))
    bb = list(map(int, input().split()))
    a_num = 0
    b_num = 0
    time_sum = 0
    counter = 0
    if bb[b_num] >= aa[a_num]:
        if k < aa[a_num]:
            return counter
    if bb[b_num] <= aa[a_num]:
        if k < bb[b_num]:
            return counter

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

    for i in range(n+m):
        if len(bb) == b_num and len(aa) == a_num:
            print('test')
            break
        if len(bb) == b_num:
            time_sum += aa[a_num]
            a_num += 1
        elif len(aa) == a_num:
            time_sum += bb[b_num]
            b_num += 1
        elif aa[a_num] > bb[b_num]:
            time_sum += bb[b_num]
            b_num += 1
        else:
            time_sum += aa[a_num]
            a_num += 1

        if time_sum > k:
            break
        counter += 1

    return counter


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

time0 = 0
cnt = 0
while(time0<=K):
    if len(A) == 0 and len(B) != 0:
        time0 += B.pop(0)
        cnt += 1
    elif len(B) == 0 and len(A) != 0:
        time0 += A.pop(0)
        cnt += 1
    elif len(A) == 0 and len(B) == 0:
        cnt += 1
        break
    else:
        if A[0] <= B[0]:
            time0 += A.pop(0)
            cnt += 1
        else:
            time0 += B.pop(0)
            cnt += 1
            
cnt -= 1

print(cnt)

Submission status: Wrong Answer

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

while sum(sum_time) <= k:
    if len(a) == 0 and len(b) == 0:
        break
    elif len(a) == 0:
        sum_time.appendleft(b.popleft())
    elif len(b) == 0:
        sum_time.appendleft(a.popleft())
    elif a[0] <= b[0]:
        sum_time.appendleft(a.popleft())
    else:
        sum_time.appendleft(b.popleft())

if sum(sum_time) > k:
    sum_time.pop()

print(len(sum_time))

Submission status: Wrong Answer

Solution code:
from collections import deque
N, M, K = map(int, input().split())
*A, = map(int, input().split())
*B, = map(int, input().split())
a = deque(A)
b = deque(B)
ans = 0
l = len(a) + len(b)
while a and b:
    if K - a[0] >= 0 or K - b[0] >= 0:
        if a[0] > b[0]:
            x = b.popleft()
            K = K - x
            ans += 1
        elif a[0] <= b[0]:
            x = a.popleft()
            K = K - x
            ans += 1
    else:
        break
C = list(a) + list(b)
c = deque(C)
while c:
    if K - c[0] >= 0:
        x = c.popleft()
        K = K - x
        ans += 1
    else:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
s_a = [0]*(n+1)
s_b = [0]*(m+1)
for i in range(1,n+1):
    s_a[i] = s_a[i-1] + a[i-1]
for i in range(1,m+1):
    s_b[i] = s_b[i-1] + b[i-1]
import bisect
Sa = bisect.bisect_right(s_a,k) -1
Sb = bisect.bisect_right(s_b,k) -1

ans = Sa
e = len(s_a)
for i in range(1,Sa+1):
    x = k - s_a[Sa-i]
    y = bisect.bisect_right(s_b,x)
    ans = max(ans,y+Sa-i)
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 = 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(ans-1)

Submission status: Wrong Answer

Solution code:
def main():
    n, m, k = [int(e) for e in input().split()]
    A = [int(e) for e in input().split()]
    B = [int(e) for e in input().split()]

    ans = 0
    t = 0
    ai, bi = 0, 0
    la, lb = len(A), len(B)
    while True:
        if ai < la and bi < lb:
            if A[ai] < B[bi]:
                t += A[ai]
                ai += 1
            else:
                t += B[bi]
                bi += 1
        elif ai < la:
            t += A[ai]
            ai += 1
        elif bi < lb:
            t += B[bi]
            bi += 1
        else:
            if t < k:
                ans += 1
            break

        if t > k:
            break

        ans += 1

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from collections import deque
def main():
    N, M, K = map(int, input().split())
    A = deque(list(map(int, input().split())))
    B = deque(list(map(int, input().split())))
    ans = 0
    a_is_available = True
    b_is_available = True
    while K >= 0:
        lenA = len(A)
        lenB = len(B)
        if lenA == 0: a_is_available = False
        if lenB == 0: b_is_available = False
        if not a_is_available and not b_is_available:
            ans += 1
            break
        if a_is_available:a = A.popleft()
        if b_is_available:b = B.popleft()
        if a_is_available and not b_is_available:
            K -= a
        elif not a_is_available and b_is_available:
            K -= b
        elif a <= b:
            K -= a
            B.appendleft(b)
        else:
            K -= b
            A.appendleft(a)
        ans += 1
    ans -= 1
    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()))

list = a + b
list = sorted(list)


m = 0
count = 0

for i in range(n + m):
    if count < k:
        count += list[i - 1]
        m += 1
        
print(m)

Submission status: Wrong Answer

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


def solve(N: int, M: int, K: int, A: "List[int]", B: "List[int]"):
    sumA = []
    sumB = []

    sum = 0
    for i in range(N):
        sum += A[i]
        if sum > K:
            break
        sumA.append(sum)

    sum = 0
    for i in range(M):
        sum += B[i]
        if sum > K:
            break
        sumB.append(sum)

    #print(K)
    #print(sumA)
    #print(sumB)

    books = 0
    for i in range(len(sumA)):
        t = K-sumA[i]
        #print(t)
        if t<=0:
            break
        idx = np.searchsorted(sumB, t, side="right")
        #print("A: {}, B: {}, books:{}".format(i+1, idx, (i+idx+1)))
        books = max(books, i+idx+1)
    
    print(books)
    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:
n,m,k=map(int,input().split())
l1=list(map(int,input().split()))
l2=list(map(int,input().split()))
a,b=l1[0],l2[0];c=0;x,y=0,0
while(k>0):
  if x<len(l1) and y<len(l2) and min(l1[x],l2[y])<=k:
    k=k-min(l1[x],l2[y]);
    if l1[x]<l2[y]:
      x+=1;
    else:
      y+=1;
  elif x<len(l1) and l1[x]<=k:
    k=k-l1[x];
    x=x+1;
  elif y<len(l2) and l2[y]<=k:
    k=k-l2[y];
    y=y+1;
  else:
    break;
  c=c+1;
print(c)

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
aa = 0
bb = 0
while True:
    if aa >= n and bb >= m:
        break
    elif aa >= n:
        k -= b[bb]
        bb += 1
    elif bb >= m:
        k -= a[aa]
        aa += 1
    else:        
        if a[aa] > b[bb]:
            k -= b[bb]
            bb += 1
        else:
            k -= b[bb]
            bb += 1        
    if k < 0:
      break

if k < 0:
	print(aa+bb-1)
else:
    print(aa+bb)