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
# -*- coding: utf-8 -*-

import itertools


def main():
    n, m, k = map(int, input().split())
    a_list = list(map(int, input().split()))
    b_list = list(map(int, input().split()))

    a_sum = b_sum = 0
    a_i = b_i = 0
    while a_i < len(a_list) and a_sum + a_list[a_i] <= k:
        a_sum += a_list[a_i]
        a_i += 1
    ans = a_i

    while a_i > 0:
        a_sum -= a_list[a_i - 1]
        while b_i < len(b_list) and a_sum + b_sum + b_list[b_i] <= k:
            b_sum += b_list[b_i]
            b_i += 1
            ans = max(ans, a_i + b_i)
        a_i -= 1

    while b_i < len(b_list) and a_sum + b_sum + b_list[b_i] <= k:
        b_sum += b_list[b_i]
        b_i += 1
        ans = max(ans, a_i + b_i)

    print(ans)


if __name__ == '__main__':
    main()

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:
n, m, k = [int(v) for v in input().split()]
alist = [int(v) for v in input().split()]
blist = [int(v) for v in input().split()]

consumed = 0
max_count = 0

i = 0
while i < len(alist) and consumed + alist[i] <= k:
    consumed += alist[i]
    i += 1

count = i
i -= 1

j = 0
while j < len(blist) and consumed + blist[j] <= k:
    consumed += blist[j]
    j += 1

count += j
max_count = count

j -= 1

while i >= 0:
    consumed -= alist[i]
    count -= 1
    while j < len(blist) and consumed + blist[j] <= k:
        consumed += blist[j]
        j += 1
        count += 1
        if count > max_count:
            max_count = count
    i -= 1

print(max_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()))
aa = [0] 
bb = [0]
for i in range(m):
    bb.append(bb[-1]+B[i])
for i in range(n):
    aa.append(aa[-1]+A[i])
aa.append(aa[-1]+1)
bb.append(bb[-1]+1)

#print(aa)
val =0
a = 0
ans = 0
ma = 0
for i in range(n+1):
    temp = k-aa[i]
    if temp<=0:

        break
    s = 0
    l = m+1
    mid = l//2
    while l-s>1:
        if temp>=bb[mid]:
            s = mid
            mid = (s+l)//2
        else:
            l = mid
            mid = (s+l)//2
    #print(s)
    #print(ans, s+i)
    ans = max(ans, s+i)
print(ans)

Submission status: Wrong Answer

Solution code:
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
a=[0]*N
b=[0]*M
a[0]=A[0]
b[0]=B[0]
for i in range(N-1):
    a[i+1]=a[i]+A[i]
for i in range(M-1):
    b[i+1]=b[i]+B[i]
diff=2*10**9
count=0
for i in range(N):
    for j in range(M):
        if 0<K-(a[i]+b[j])<diff:
            diff=K-(a[i]+b[j])
            count=(i+1)+(j+1)
print(count)

Submission status: Wrong Answer

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

a_i=0
b_i=0
cnt = 0
t = 0
while(k >= t):
    if(n==a_i and m==b_i):
        break
    if(n==a_i):
        t += B[b_i]
        if(t > k):
            break
        b_i += 1
        cnt += 1
        continue
    if(m==b_i):
        t += A[a_i]
        if(t > k):
            break
        a_i += 1
        cnt += 1
        continue
    
    if(A[a_i] > B[b_i]):
        now = B[b_i]
        b_i += 1
    else:
        now = A[a_i]
        a_i += 1
    t += now
    if(t > k):
        break
    cnt += 1


print(cnt)

Submission status: Wrong Answer

Solution code:
'''
.append(要素) リストに要素を追加
.extend(リスト) リストを連結する
.insert(場所,要素) 指定した場所に要素追加
del 配列名[場所]
-1で末尾で末尾から一つ前

sort()
sorted(reverse=true)

配列の初期化
配列名=[a]*n+[b]*m

Decimal()
'''

from sys import stdin
from itertools import accumulate, dropwhile, takewhile, groupby
import bisect
import copy
import math
from functools import reduce
from operator import mul
from collections import Counter
import itertools
import fractions
import sys

d1 = stdin.readline().rstrip().split()
N = int(d1[0])
M = int(d1[1])
K = int(d1[2])
A = [int(s) for s in stdin.readline().rstrip().split()]
B = [int(s) for s in stdin.readline().rstrip().split()]

count = 0
minute = 0
posA = 0
posB = 0
while(True):
    if A[-1] == 0 and B[-1] == 0:
        break
    if minute >= K:
        count -= 1
        break
    if A[-1] != 0 and (B[-1] == 0 or A[posA] <= B[posB]):
        minute += A[posA]
        A[posA] = 0
        posA += 1
        count += 1
        continue
    if B[-1] != 0 and(A[-1] == 0 or A[posA] > B[posB]):
        minute += B[posB]
        B[posB] = 0
        posB += 1
        count += 1
        continue
print(count)

Submission status: Wrong Answer

Solution code:
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n,m,k = map(int,ipt().split())
    a = [int(i) for i in ipt().split()]
    b = [int(i) for i in ipt().split()]
    an = n
    bn = m
    sm = 0
    for i,ai in enumerate(a):
        if sm+ai > k:
            an = i
            break
        sm += ai
    for i,bi in enumerate(b):
        if sm+bi > k:
            bn = i
            break
        sm += bi
    ma = an+bn
    for i in range(an):
        ai = a[an-1-i]
        sm -= ai
        for j in range(bn,m):
            if sm+bn > k:
                bn = j
                break
            elif j == m-1:
                bn = m
            sm += b[j]
        if ma < an-i-1+bn:
            ma = an-i-1+bn
        if bn == m:
            print(ma)
            exit()
    print(ma)


    return

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = abs(n-m)
ans = 0
count = 0

if (sum(a) + sum(b)) <= k:
  exit(print(len(a) + len(b)))
  
if n > m:
  for i in range(c):
    b.append(10000000000)
else:
  for i in range(c):
    a.append(10000000000)

while True:
  if a[0] <= b[0]:
    print(a[0])
    ans += a[0]
    count += 1
    a.pop(0)
    if ans > k:
      print(count - 1)
      break
  else:
    print(b[0])
    ans += b[0]
    count += 1
    b.pop(0)
    if ans > k:
      print(count - 1)
      break

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
from bisect import bisect_right

n,m,k = map(int, input().split())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))

a_cumsum = list(accumulate(a_list))

b_cumsum = list(accumulate(b_list))

ans=0
for i in range(n):
  if k<a_cumsum[i]:
    continue
  b_max=k-a_cumsum[i]
  b_index = bisect_right(b_cumsum, b_max)-1
  koho=i+1+b_index+1
  ans = max(ans,koho)

  
  
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()))
ans1 = 0
for i in range(n-1):
    a[i+1] = a[i]+a[i+1]
for i in range(m-1):
    b[i+1] = b[i]+b[i+1]
import bisect
key = bisect.bisect(a,k)
for i in range(key+1):
    ans = 0
    ans += key
    time = a[key-i-1]
    ans += bisect.bisect(b,k-time)
    ans1 = max(ans1,ans)

            
print(ans1)

Submission status: Wrong Answer

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

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


from itertools import accumulate
aacc = [0] + a
aacc = list(accumulate(aacc))
bacc = [0] + b
bacc = list(accumulate(bacc))

from bisect import bisect_right
ans = 0
for i, ac in enumerate(aacc):
    if k-ac>0:
        index = bisect_right(bacc, max(0,k-ac))
        ans = max(ans, i+index-1)

print(ans)

Submission status: Wrong Answer

Solution code:
m,n,size = list(map(int,input().split(" ")))

a = list(map(int,input().split(" ")))
b = list(map(int,input().split(" ")))
temp = []
j = 0
k=0
for i in range(len(a)+len(b)):
    if j <len(a):
        temp.append(a[j])
        j+=1
    if k <len(b):
        temp.append(b[k])
        k+=1
c = 0
sum = 0
flag = 0
for i in temp:
    sum += i
    if sum>=size:
        flag =1
    c += 1
    if flag ==1:
        break
print(c)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def helper(n, m, k, a, b):
	i = 0
	j = 0
	while i < n and j < m:
		if min(a[i], b[j]) > k:
			return i + j
		if a[i] < b[j]:
			k -= a[i]
			i += 1
		elif a[i] >= b[j]:
			k -= b[j]
			j += 1
	while i < n:
		if a[i] > k:
			return i + j
		k -= a[i]
		i += 1

	while j < m:
		if b[j] > k:
			return i + j
		k -= b[j]
		j += 1
	return i + j

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

r = 0
# while n != 0 and m != 0:
# 	if a[0] > k and b[0] > k:
# 		break
# 	if a[0] < b[0]:
# 		n -= 1
# 		k -= a[0]
# 		a.pop(0)
# 		r += 1
# 	elif a[0] >= b[0]:
# 		m -= 1
# 		k -= b[0]
# 		b.pop(0)
# 		r += 1

# while n != 0:
# 	if a[0] > k:
# 		break
# 	n -= 1
# 	k -= a[0]
# 	a.pop(0)
# 	r += 1

# while m != 0:
# 	if b[0] > k:
# 		break
# 	m -= 1
# 	k -= b[0]
# 	b.pop(0)
# 	r += 1

r = helper(n, m, k, a, b)
print (str(r))

Submission status: Wrong Answer

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

A.append(1000000000)
B.append(1000000000)

time = 0
ans = 0

i, j = 0, 0
if A[0]>K and B[0]>K:
    print(0)
    sys.exit()
else:
    for _ in range(len(A)+len(B)-2):
        if A[i] <=B[j]:
            time += A[i]
            if time <=K:
                ans += 1
                i += 1
            else:
                break
        elif A[i] >= B[j]:
            time += B[j]
            if time <= K:
                ans += 1
                j += 1
            else:
                break
        #print(i,j,time)
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()))
    # A.reverse()
    # B.reverse()

    q_a = deque(A)
    q_b = deque(B)
    cnt = 0
    time = 0
    for _ in range(n + m):
        if q_a:
            a = q_a.popleft()
        else:
            a = None

        if q_b:
            b = q_b.popleft()
        else:
            b = None

        #print(a,b)

        if a and b:
            # aの方が読みやすい
            if a < b:
                q_b.appendleft(b)
                time += a

            # bの方が読みやすい
            if b <= a:
                q_a.appendleft(a)
                time += b
        else:
            if a:
                time += a
            if b:
                time += b

        #print(q_a,q_b,time)
        # 制限時間オーバー
        if time > k:
            break

        cnt += 1

    print(cnt)














if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np

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

a = input().split()
np_a=np.array(a, dtype=int)
b = input().split()
np_b=np.array(b, dtype=int)

ia=0
ib=0
time=0
hon=n+m
for i in range(0,n+m):
  if (ia == n): 
    time+=np_b[ib]
    ib+=1
  elif (ib == m): 
    time+=np_a[ia] 
    ia+=1
  elif (ia < n or ib < m): 
    if (np_a[ia] <= np_b[ib]):
      time+=np_a[ia]
      ia+=1
    else:
      time+=np_b[ib]
      ib=+1

  if (time > k): 
    hon=i
    break

print (hon)

Submission status: Wrong Answer

Solution code:
import bisect

N,M,K = map(int,input().split())
AList = list(map(int,input().split()))
BList = list(map(int,input().split()))

AList.append(10**10)
BList.append(10**10)

ASList = [AList[0]]
for i in range(1,N+1):
  a = ASList[-1] + AList[i]
  ASList.append(a)

BSList = [BList[0]]
for i in range(1,M+1):
  a = BSList[-1] + BList[i]
  BSList.append(a)  
  
ans = 0
for i in range(M):
  b = BSList[i]
  c = K-b
  if c > 0:
    d = bisect.bisect_left(ASList,c)
    if ASList[d] == c:
      d +=1 
    ans = max(ans,i+d+1)
  else:
    d = bisect.bisect_left(ASList,K)
    ans = max(ans,d)
  
print(int(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()))

ans = 0
a_ind = 0
b_ind = 0
while k > 0:
    if n > a_ind and m > b_ind:
        if a[a_ind] < b[a_ind]:
            if k >= a[a_ind]:
                k -= a[a_ind]
                a_ind += 1
                ans += 1
            else:
                break
        else:
            if k >= b[b_ind]:
                k -= b[b_ind]
                b_ind += 1
                ans += 1
            else:
                break
    elif n > a_ind and m == b_ind:
        if k >= a[a_ind]:
            k -= a[a_ind]
            a_ind += 1
            ans += 1
        else:
            break
    elif n == a_ind and m > b_ind:
        if k >= b[b_ind]:
            k -= b[b_ind]
            b_ind += 1
            ans += 1
        else:
            break
    else:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
import heapq

def solve(A, B, K):

    N = len(A)
    M = len(B)

    min_heap = []

    A_MARKER, B_MARKER = 0, 1
    heapq.heappush(min_heap, (A[0], A[1] if len(A) > 1 else float('inf'), A_MARKER, 0))
    heapq.heappush(min_heap, (B[0], B[1] if len(B) > 1 else float('inf'), B_MARKER, 0))

    k = 0
    count = 0
    while k < K and min_heap:

        mins, nxt_mins, marker, idx = heapq.heappop(min_heap)
        if k + mins > K:
            return count

        k += mins
        count += 1

        if marker == A_MARKER and idx + 1 < N:
            nxt_nxt_mins = A[idx + 2] if len(A) > idx + 2 else float('inf')
            heapq.heappush(min_heap, (nxt_mins, nxt_nxt_mins, A_MARKER, idx + 1))
        elif marker == B_MARKER and idx + 1 < M:
            nxt_nxt_mins = B[idx + 2] if len(B) > idx + 2 else float('inf')
            heapq.heappush(min_heap, (nxt_mins, nxt_nxt_mins, B_MARKER, idx + 1))

    return count

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

print(solve(A, B, K))

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()))
csum=0
for i in range(N+M):
    try:
        a=A[0]
    except:
        a=1000000001
    try:
        b=B[0]
    except:
        b=1000000001
    if a>b:
        pop=B.pop(0)
        csum+=pop
    else:
        pop=A.pop(0)
        csum+=pop
    if csum==K:
        count=i+1
        break
    elif csum>K:
        count=i
        break
print(count)

Submission status: Wrong Answer

Solution code:
a=input().split(" ")
b=input().split(" ")
c=input().split(" ")
d=0
e=0
f=0
count=0
while int(a[2])>=e and int(a[2])>=int(b[0]):
    if d<int(a[0]):
        e=e+int(b[d])
        d=d+1
        count+=1
    elif f<int(a[1]) and d>=3:
        e=e+int(c[f])
        f=f+1
        count+=1
    elif d>int(a[0]) and f>int(a[1]):
        break
    else:
        break

print(count)

Submission status: Wrong Answer

Solution code:
count = 0

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

a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]

a_b = []

while(True):
    if(len(a) == 0 and len(b) == 0):
        break
    if(len(a) == 0):
        a_b.append(b.pop(0))
        continue
    if(len(b) == 0):
        a_b.append(a.pop(0))
        continue
    tmp_a = a[0]
    tmp_b = b[0]
    if tmp_a > tmp_b:
        a_b.append(b.pop(0))
    else:
        a_b.append(a.pop(0))

for tmp in a_b:
    k -= tmp
    if k < 0:
        break
    count += 1

print(count)

Submission status: Wrong Answer

Solution code:
import math
#map(int,input().split())
#int(x) for x in input().split()
#for _ in range(int(input())):
n,m,k=map(int,input().split())
a=[int(x) for x in input().split()]
b=[int(x) for x in input().split()]
pa=[0]*n
pb=[0]*m
pa[0]=a[0]
pb[0]=b[0]
for i in range(1,n):
	pa[i]=pa[i-1]+a[i]
for i in range(1,m):
	pb[i]=pb[i-1]+b[i]

i=n-1
j=m-1
ans=0
while i>=0:
	if ans>=i+1+i+1:
		break
	if pa[i]>k:
		i-=1
		continue
	j=m-1
	while j>=0:
		if ans>=i+1+j+1:
			break
		if pa[i]+pb[j]<=k:
			ans=max(ans,i+1+j+1)
			break
		else:
			j-=1
	i-=1

j=m-1
while j>=0:
	if ans>=j+1+j+1:
		break
	if pb[i]>k:
		j-=1
		continue
	i=n-1
	while i>=0:
		if ans>=i+1+j+1:
			break
		if pa[i]+pb[j]<=k:
			ans=max(ans,i+1+j+1)
			break
		else:
			i-=1
	j-=1
print(ans)

Submission status: Wrong Answer

Solution code:
# AtCoder
from collections import deque
N, M, K = map(int, input().split())
A = deque(map(int, input().split()))
B = deque(map(int, input().split()))

ans = 0
count = 0
while K >= count:
    if len(A) != 0 and len(B) != 0:
        if A[0] > B[0]:
            t = B.popleft()
        else:
            t = A.popleft()
    elif len(A) == 0 and len(B) != 0:
        t = B.popleft()
    elif len(B) == 0 and len(A) != 0:
        t = A.popleft()

    count += t
    if 0 > K - count:
        break
    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()))

time = 0
ai = 0
bi = 0
while (time < K):
  if (ai < N and bi < M): #AにもBにも本がまだのこっているとき
    if (A[ai] < B[bi]): #Aのほうが時間が短い
      if(time + A[ai] <= K):
        time += A[ai]
        ai += 1
      else: 
        break
    else: #Bのほうが時間が短い
      if (time + B[bi] <= K):
        time += B[bi]
        bi += 1
      else:
        break
  elif (ai == N and bi < M): #Aに本がなくなってBに本があるとき
    if (time + B[bi] <= K):
      time += B[bi]
      bi += 1
    else:
      break
  elif (ai < N and bi == M): #Bに本がなくなってAに本があるとき
    if (time + A[ai] <= K):
      time += A[ai]
      ai += 1
    else:
      break
  else: #AにもBにも本がないとき
    break
print(ai+bi)

Submission status: Wrong Answer

Solution code:
MAX=10**9+1
def main(n, m, k, a_n, b_n):
    a_n.append(MAX)
    b_n.append(MAX)

    r = 0
    a = 0
    b = 0
    for _ in range(n+m):
        a_v = a_n[a]
        b_v = b_n[b]

        if a_v == MAX and b_v == MAX:
            return r

        if a_v < b_v:
            k -= a_n[a]
            a += 1
        else:
            k -= b_n[b]
            b += 1

        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
x=input()
x0=x.split()
n=int(x0[0])
m=int(x0[1])
k=int(x0[2])
a=input()
b=input()
a0=[int(i) for i in a.split()]
b0=[int(i) for i in b.split()]
a=0
b=0
al=list([0])
bl=list([0])
for i in range(n):
    a=a+a0[i]
    if a>k:
        break
    al.append(a)
for i in range(m):
    b=b+b0[i]
    if b>k:
        break
    bl.append(b)
for i in range(len(al)):
    for l in range(len(bl)):
        if al[-i-1]+bl[-l-1]<=k:
            print(len(al)+len(bl)-i-l-2)
            sys.exit()
        if al[-i-1]+bl[1]>k:
            break

Submission status: Wrong Answer

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

ans = 0
ai = 0
bi = 0
t = 0
for i in range(n+m):
  if t > k:
    break
  if ai >= n:
    t += b_list[bi]
    bi += 1
    ans += 1
  elif bi >= m:
    t += a_list[ai]
    ai += 1
    ans += 1
  elif a_list[ai] > b_list[bi]:
    t += b_list[bi]
    bi += 1
    ans += 1
  else:
    t += a_list[ai]
    ai += 1
    ans += 1
if t <= k:
  print(ans)
else:
  print(ans-1)

Submission status: Wrong Answer

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

AB = list()
a = 0
b = 0
for i in range(N+M):
  if (((a+1) <= N) and ((b+1) <= M)):
    if(A[a] < B[b]):
      AB.append(A[a])
      a += 1
    else:
      AB.append(B[b])
      b += 1
  elif((a+1) > N):
    for j in range(M-b):
      AB.append(B[b])
      b += 1
    break
  elif((b+1) > M):
    for j in range(N-a):
      AB.append(A[a])
      a += 1
    break

ans = 0
ab = 0
i = 0
while K >= 0:
  K -= AB[ans]
  ans += 1
  if(ans == (N+M)):
    print(N+M)
    sys.exit()
  
print(ans-1)

Submission status: Wrong Answer

Solution code:
N, M, K = (int(s) for s in input().rstrip().split())

A = [int(s) for s in input().rstrip().split()]
B = [int(s) for s in input().rstrip().split()]

i, j = (0, 0)
sum, count = (0, 0)

while sum < K and (i + j < N + M):
  if i < N and j < M:
    if A[i] <= B[j]:
      sum += A[i]
      i += 1
      count += 1
    else:
      sum += B[j]
      j += 1
      count += 1
  elif i < N:
    sum += A[i]
    i += 1
    count += 1
  else:
    sum += B[j]
    j += 1
    count += 1

if sum > K:
  count -= 1
    
print(count)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys

N,M,K = list(map(int, input().rstrip().split()))
A_list = list(map(int, input().rstrip().split()))
B_list = list(map(int, input().rstrip().split()))
#-----

i_a = 0
i_b = 0
time = 0
cnt = 0

while i_a < len(A_list)  and  i_b < len(B_list):
    if A_list[i_a] <= B_list[i_b]:
        time += A_list[i_a]
        i_a += 1
        cnt += 1
    else:
        time += B_list[i_b]
        i_b += 1
        cnt += 1
    
    if time > K:
        print(cnt -1)
        sys.exit()


if i_a == len(A_list)  and  i_b < len(B_list):
    i_x = i_b
    X = B_list
elif i_a < len(A_list)  and  i_b == len(B_list):
    i_x = i_a
    X = A_list


while i_x < len(X):
    time += X[i_x]
    i_x += 1
    cnt += 1
    
    if time > K:
        print(cnt -1)


print(cnt)

Submission status: Wrong Answer

Solution code:
from heapq import merge 
m,n,k=map(int,input().split())
l=list(map(int,input().split()))
li=list(map(int,input().split()))
r=list(merge(l,li)) 
z,ans=0,0
for i in r:
  if z+i<=k:
    z+=i
    ans+=1
  else:
    break
print(ans)

Submission status: Wrong Answer

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


while True:
    if sum(ans) > k:
        print(len(ans) - 1)
        break
    if a[0] + b[0] == 2 * (10 ** 9 + 1):
        print(len(ans))
        break
    
    if a[0] > b[0]:
        ans += [b.popleft()]
        
    else:
        ans += [a.popleft()]
    if len(a) == 0 or len(b) == 0:
        a.append(10 ** 9 + 1)
        b.append(10 ** 9 + 1)

Submission status: Wrong Answer

Solution code:
from collections import deque

n, m, k = map(int, input().split())
la = deque(list(map(int, input().split())))
lb = deque(list(map(int, input().split())))

cnt = 0
while k >= 0:
    if la == deque([]):
        if lb == deque([]):
            break
        elif lb[0] <= k:
            k -= lb[0]
            cnt += 1
            lb.popleft()
        else:
            break
    elif lb == deque([]):
        if la[0] <= k:
            k -= la[0]
            cnt += 1
            la.popleft()
        else:
            break
    elif la[0] > lb[0]:
        if lb[0] <= k:
            k -= lb[0]
            cnt += 1
            lb.popleft()
        else:
            break
    elif la[0] <= lb[0]:
        if la[0] <= k:
            k -= la[0]
            cnt += 1
            la.popleft()
        else:
            break

print(cnt)

Submission status: Wrong Answer

Solution code:
def problem():
    n, m, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    ans = 0
    t = 0
    n = -1 * n
    m = -1 * m

    while k > t:
        if n == 0 and m == 0:
            return ans
        if n == 0 and m != 0:
            t += b[m]
            ans += 1
            m += 1
        if n != 0 and m == 0:
            t += a[n]
            ans += 1
            n += 1
        if n != 0 and m != 0:
            if a[n] >= b[m]:
                t += b[m]
                ans += 1
                m += 1
            else:
                t += a[n]
                ans += 1
                n += 1
        if k < t:
            return ans-1
    return ans

print(problem())

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
A_count = 0
B_count = 0
ans = 0

f_inf = float('inf')
A.append(f_inf)
A.append(f_inf)
B.append(f_inf)
B.append(f_inf)

for i in range(N+M):
    if A_count >= N and B_count >= M:
        break

    if A[A_count] < B[B_count]:
        time -= A[A_count]
        if time < 0:
            break
        A_count += 1
        ans += 1
    elif A[A_count] > B[B_count]:
        time -= B[B_count]
        if time < 0:
            break
        B_count += 1
        ans += 1
    else:
        if A[A_count+1] < B[B_count+1]:
            time -= A[A_count]
            if time < 0:
                break
            A_count += 1
            ans += 1
        else:
            time -= B[B_count]
            if time < 0:
                break
            B_count += 1
            ans += 1

# if A_count >= N and B_count >= M:
# while time >= 0:
#     if A_count < N:
#         time -= A[A_count]
#         if time < 0:
#             break
#         ans += 1
#         A_count += 1
#     if B_count < M:
#         time -= B[B_count]
#         if time < 0:
#             break
#         ans += 1
#         B_count += 1

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

    q_a = deque(A)
    q_b = deque(B)
    cnt = 0
    time = 0
    for _ in range(n + m):
        if q_a:
            a = q_a.popleft()
        else:
            a = None

        if q_b:
            b = q_b.popleft()
        else:
            b = None

        print(a,b)

        if a and b:
            # aの方が読みやすい
            if a < b:
                q_b.appendleft(b)
                time += a

            # bの方が読みやすい
            if b <= a:
                q_a.appendleft(a)
                time += b
        else:
            if a:
                time += a
            if b:
                time += b

        #print(q_a,q_b,time)
        # 制限時間オーバー
        if time > k:
            break

        cnt += 1

    print(cnt)














if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import deque
N,M,K = map(int, input().split())
A= list(map(int, input().split()))
B = list(map(int, input().split()))
a=0
b=0
#C=[0]*200000
#A=A+C
#B=B+C
a1=deque(A)
b1=deque(B)
honn=0
time=0
for i in range(N+M):
    if  len(a1)>0 and len(b1)>0:
        if a1[0]>b1[0]:
            r=b1.popleft()
            time+=r
            if not time>K:
                honn+=1
                continue
            else:
                break
        if a1[0]<b1[0]:
            r=a1.popleft()
            time+=r
            if not time>K:
                honn+=1
                continue
            else:
                break

        if a1[0]==b1[0]:
            r=a1.popleft()
            time+=r
            if not time>K:
                honn+=1
                continue
            else:
                break
    if len(a1)>0 and len(b1)==0:
        r=a1.popleft()
        time+=r
        if not time>K:
            honn+=1
            continue
        else:
            break
    if len(a1)==0 and len(b1)>0:
        r=b1.popleft()
        time+=r
        if not time>K:
            honn+=1
            continue
        else:
            break           
print(honn)

Submission status: Wrong Answer

Solution code:
from collections import deque
N, M, K = map(int,input().split())
al = list(map(int,input().split()))
bl = list(map(int,input().split()))
al = deque(al)
bl = deque(bl)

time = 0
cnt = 0
while time <= K :
    # 両方とも残りがある
    if len(al) >= 1 and len(bl) >= 1:
        if al[0] <= bl[0]:
            time += al[0]
            al.popleft()
            cnt += 1
        else:
            time += bl[0]
            bl.popleft()
            cnt += 1
    # alしか残っていない
    elif len(al) >= 1:
        time += al[0]
        al.popleft()
        cnt += 1
    # blしか残っていない
    elif len(bl) >= 1:
        time += bl[0]
        bl.popleft()
        cnt += 1
    #何も残っていない
    else:
        break
if time <= K:
    print(cnt)
else:
    print(cnt-1)