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:
import itertools
import bisect

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

aa = [0] + list(itertools.accumulate(A))
bb = [0] + list(itertools.accumulate(B))

ans = bisect.bisect_left(aa, K)-1
ans = max(ans, bisect.bisect_left(bb, K)-1)

for i in reversed(range(N+1)):
    tmp_K = K-aa[i]
    if tmp_K == 0:
        ans = max(ans, i)
    elif tmp_K < 0:
        continue

    if i + M <= ans:
        continue

    if (ans-i+1) >= 0 and bb[(ans-i+1)] >= tmp_K:
        continue

    if tmp_K >= bb[-1]:
        ans = max(ans, i+M)
        continue

    ans = max(ans, bisect.bisect_left(bb, tmp_K)-1+i)
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
from collections import deque

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

x = deque()
x.append(0)
for i in range(n + m):
    num = 0
    if len(a) == 0:
        num = b.popleft()
    elif len(b) == 0:
        num = a.popleft()
    elif a[0] <= b[0]:
        num = a.popleft()
    else:
        num = b.popleft()
    x.append(num + x[-1])

x.popleft()

pos = bisect.bisect_right(x, k)
print(pos)

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

x = [0, a[0]]
y = [0, b[0]]
for i in range(1, n):
    x.append(x[i] + a[i])
for i in range(1, m):
    y.append(y[i] + b[i])
    
i = 0
j = 0
ans = 0
while i < n or j < m:
    if i < n and x[i] <= y[j]:
        i += 1
    elif j < m:
        j += 1
    if x[i] + y[j] > k:
        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
ia = 0
ib = 0

while time <= k:
    if ia >= len(a) and ib >= len(b):
        break
    elif ia >= len(a):
        time += b[ib]
        ib += 1
    elif ib >= len(b):
        time += a[ia]
        ia += 1
    elif a[ia] <= b[ib]:
        time += a[ia]
        ia += 1
    else:
        time += b[ib]
        ib += 1

if time > k:
    print(ia + ib - 1)
else:
    print(ia + ib)

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
books = 0
A.append(200001)
B.append(200002)

while time <= K:
    if A[0] < B[0]:
        time += A.pop(0)
    elif B[0] < A[0]:
        time += B.pop(0)
    elif B[0] == A[0]:
        if B[1] > A[1]:
            time += A.pop(0)
        else:
            time += B.pop(0)
    books += 1
if books == 0:
    print(0)
else:
    print(books - 1)

Submission status: Wrong Answer

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

a_i= 0
b_i= 0
f = True

if sum(a)+sum(b) <= k:
    print(n+m)
    exit()

for i in range(n+m):
    # print(a_i,b_i,k) 
    if a[a_i] < b[b_i]:
        k -= a[a_i]
        if k < 0:
            print(a_i+b_i)
            exit()
        a_i += 1
        if a_i == n:
            for j in range(m):
                # print(a_i,b_i,k)
                k -= b[b_i]
                if k < 0:
                    print(a_i+b_i)
                    exit()
                b_i += 1
    else:
        k -= b[b_i]
        if k < 0:
            print(a_i+b_i)
            exit()
        b_i += 1
        if b_i == m:
            for j in range(n):
                # print(a_i,b_i,k)
                k -= a[a_i]
                if k < 0:
                    print(a_i+b_i)
                    exit()
                a_i += 1

Submission status: Wrong Answer

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

def main():
    n,m,k = map(int,input().split())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    a_cum = numpy.cumsum(a).tolist()
    b_cum = numpy.cumsum(b).tolist()
    a_cum.insert(0,0)
    b_cum.insert(0,0)
    ans_i = 0
    for i,c in enumerate(a_cum):
        for j,d in enumerate(b_cum):
            if c + d <= k and ans_i <= c + d:
                ans = i + j
                ans_i = c + d
            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()))

import numpy as np

a =[]
flag = True
while flag:
    if not A and not B:
        flag = False
    elif not A:
        a.append(B[0])
        B = B[1:]
    elif not B:
        a.append(A[0])
        A = A[1:]
    elif A[0] <= B[0]:
        a.append(A[0])
        A = A[1:]
    #elif A[0] > B[0]:
    else:
        a.append(B[0])
        B = B[1:]
    
    
    
    

res = np.cumsum(a)
r = list(res)

cnt = 0
for i in r:
    if i <= K:
        cnt += 1
    else:
        break
print(cnt)

Submission status: Wrong Answer

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

cnt = 0

list = A + B
list = [int(s) for s in list]
list.sort()
ans = min(list)

min = int(int(K)/int(min(list)))
for s in range(len(list)):
    if ans <= int(K):
        cnt += 1
        ans += list[s]

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

for i in range(n):
    if sum(a[0:i+1])<k:
        amax += 1
        
book = amax
ans = book

for j in range(m):
    while sum(a[0:amax]) + sum(b[0:j+1]) > k and amax >= 1:
        amax -= 1
        book -= 1
    if sum(a[0:amax]) + sum(b[0:j+1]) <= k:
        book += 1
        if book > ans:
            ans = book
    else:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
import itertools

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

iter = [x for x in itertools.chain.from_iterable(itertools.zip_longest(A,B)) if x]
cnt =  0
sum = 0
for i in iter:
    sum += i
    if sum > K:
        break
    else:
        cnt +=1
print(cnt)

Submission status: Wrong Answer

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

a.append(10**10)
b.append(10**10)

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

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

j = 0
mx = 0
for i in reversed(range(n)):
    while waA[i] + waB[j] < k or j == m - 1:
        if mx < (i + 1) + (j + 1):
            mx = (i + 1) + (j + 1)
            j += 1

print(mx)

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

if len(a)>len(b):
	a,b=b,a
i=0
j=0
total=0
cnt=0
while total<k:
	if i<len(a):
		if a[i]<=b[j]:
			total+=a[i]
			i+=1
		else:
			total+=b[j]
			j+=1
	else:
		total+=b[j]
		j+=1

	cnt+=1
	if total>k:
		cnt-=1
	if j==len(b) and i==len(a):
		break

print(cnt)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**9)
 
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.append(10**10)
b.append(10**10)
 
atop = 0
btop = 0
zikan = 0
satu = 0
yomu = 0
 
while True:
    if atop >= n and btop >= m:
        break
    if a[atop] < b[btop]:
        yomu = a[atop]
        atop += 1
    elif a[atop] > b[btop]:
        yomu = b[btop]
        btop += 1
    else:
        if a[atop+1] < b[btop+1]:
            yomu = a[atop]
            atop += 1
        else:
            yomu = b[btop]
            btop += 1
    if zikan + yomu <= k:
        zikan += yomu
        satu += 1
    else:
        break
print(satu)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

a_sum = np.cumsum(np.array(a))
b_sum = np.cumsum(np.array(b))

for i in range(n+1):
    if a_sum[i] < k:
        for j in range(m+1):
            if a_sum[i] + b_sum[j] <= k:
                if num < i + j:
                    num = i+j    
            else:
                break

print(num)

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

  if sum(A) + sum(B) <= K:
    return N + M
  elif A[0] > K or B[0] > K:
    return 0

  while True:
    if A[0] < B[0]:
      tmp += A.pop(0)
      count += 1
    else:
      tmp += B.pop(0)
      count += 1
    if len(A) == 0:
      while True:
        tmp += B.pop(0)
        if tmp > K:
          return count
        count += 1
    elif len(B) == 0:
      while True:
        tmp += A.pop(0)
        if tmp > K:
          return count
        count += 1
    if tmp > K:
      return count
    
print(main())

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_tsu = [0]*N
A_eff = [0]*N
B_tsu = [0]*M
B_eff = [0]*M
A_tsu[0] = A[0]
A_eff[0] = A[0]
B_tsu[0] = B[0]
B_eff[0] = B[0]
for i in range(1, N):
    A_tsu[i] = A_tsu[i-1] + A[i-1]
    A_eff[i] = A_tsu[i]/i
for i in range(1, M):
    B_tsu[i] = B_tsu[i-1] + B[i-1]
    B_eff[i] = B_tsu[i]/i

i = N
ans = 0
for a in A_tsu[::-1]:
    if a <= K:
        j = 1
        for b in B_tsu:
            if a + b <= K:
                ans = max(ans, i+j)
            j += 1
    i -= 1
print(ans)

Submission status: Wrong Answer

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

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

cnt=0

#Aのみ読んだ場合を考える
for a in A:
  if K >= a:
    K-=a
    cnt+=1
  else:
    break

maxcnt=cnt
A=A[: cnt ]
#print(A,K)
for i,b in enumerate(B):
  #aの要素なくしてbを入れる
  #bがいれれるまでaをなくすよ
  while b>K and len(A)!=0:
    a = A.pop()
    K += a
    cnt -= 1
    #print('-a,',a,K)
    
  if len(A) == 0:
    _B=B.copy()[i:]
    _B.pop()
    #まだbが入るかもしれない…！
    while(len(_B)>0 and K>=b):
      K-=b
      cnt+=1
      #print('+b(while),',b,K,cnt)
      b=_B.pop()
    if maxcnt < cnt:
      maxcnt=cnt
    break

  K -= b
  cnt+=1
  #print('+b,',b,K,cnt)
  
  if maxcnt < cnt:
    maxcnt=cnt



print(maxcnt)

Submission status: Wrong Answer

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

L=[]
ans=0
i,j=0,0
while True:
  if A[i]<B[j]:
    L.append(A[i])
    i+=1
    if i>N-1:
      L.extend(B[j:])
      break
  else:
    L.append(B[j])
    j+=1
    if j>M-1:
      L.extend(A[i:])   
      break
LA=list(itertools.accumulate(L))

ans=bisect.bisect_right(LA,K)
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()))
totalbook = 0
totaltime = 0
for a in range(200000):
    if A[0] <= B[0]:
        tt = A.pop(0)
    else:
        tt = B.pop(0)
    if totaltime + tt <= K:
        totaltime += tt
        totalbook += 1
        A.append(200001)
        B.append(200001)
    else:
        break
print(totalbook)

Submission status: Wrong Answer

Solution code:
import numpy 
def main():
    N,M,K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    cumsA = numpy.cumsum(A)
    cumsB = numpy.cumsum(B)
    ans = 0
    for i,ca in enumerate(cumsA):
        if ca<=K:
            b=numpy.sum(cumsB<=(K-ca))
            ans=i+1+b
    print(ans)

main()

Submission status: Wrong Answer

Solution code:
n,m,k = input().split()
N = int(n)
M = int(m)
K = int(k)
a_t = input().split()
b_t = input().split()
A_Times = list()
B_Times = list()
for i in range(N):
  A_Times.append(int(a_t[i]))
for i in range(M):
  B_Times.append(int(b_t[i]))
total_time = 0
num_books = 0
while total_time<=K:
  if len(A_Times)<=0 and len(B_Times)<=0: break 
  if len(A_Times)>0 and len(B_Times)>0:
    min_time = 0
    if A_Times[0]<B_Times[0]:
      min_time = A_Times[0]
      del A_Times[0]
    else: 
      min_time = B_Times[0]
      del B_Times[0]
    if total_time+min_time<=K:
      total_time += min_time
      num_books+=1
    else:    break
  elif len(A_Times)<=0:
    min_time = B_Times[0]
    del B_Times[0]
    if total_time+min_time<=K:
      total_time += min_time
      num_books+=1
    else:    break
  else:
    min_time = A_Times[0]
    del A_Times[0]
    if total_time+min_time<=K:
      total_time += min_time
      num_books+=1
    else:    break
print(num_books)

Submission status: Wrong Answer

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

ia = 0
ib = 0
cnt = 0
ans = 0
while True:
    # print(ia,ib)
    if ia == n and ib == m:
        print(ans)
        exit()
    elif ia == n and ib < m:
        if cnt + Bs[ib] > k:
            print(ans)
            exit()
        cnt += Bs[ib]
        ib += 1
    elif ib == m and ia < n:
        if cnt + As[ia] > k:
            print(ans)
            exit()
        cnt += As[ia]
        ia += 1
    elif As[ia] < Bs[ib]:
        if cnt + As[ia] > k:
            print(ans)
            exit()
        cnt += As[ia]
        ia += 1
    else:
        if cnt + Bs[ib] > k:
            print(ans)
            exit()
        cnt += Bs[ib]
        ib += 1
    ans += 1
print(ans)

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
	else:
		break
	c += 1
print(c)

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
for i in range(N+K):
    if len(al) >= 1 and len(bl) >= 1:
        if al[0] >= bl[0]:
            time += bl.popleft()
            if time > K:
                print(cnt)
                exit()
            else:
                cnt += 1
        else:
            time += al.popleft()
            if time > K:
                print(cnt)
                exit()
            else:
                cnt += 1
    elif len(al) >= 1:
        time += al.popleft()
        if time > K:
            print(cnt)
            exit()
        else:
            cnt += 1
    elif len(bl) >= 1:
        time += bl.popleft()
        if time > K:
            print(cnt)
            exit()
        else:
            cnt += 1
    else:
        print(cnt)
        break

Submission status: Wrong Answer

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

input = sys.stdin.readline


def S():
    return input().rstrip()


def I():
    return int(input())


def MI():
    return map(int, input().split())


n, m, k = MI()
a = np.array(list(MI()))
b = np.array(list(MI()))

cuma = np.cumsum(a)
cuma = cuma[cuma <= k]
cumb = np.cumsum(b)
cumb = cumb[cumb <= k]
lena = len(cuma)
lenb = len(cumb)

id = 0
if lena == 0 and lenb == 0:
    print(0)
    exit()
elif lena == n and lenb == m:
    print(n + m)
    exit()
elif lena > lenb:
    b = b[:lenb]
    ans = lenb
    now = lenb
    for d in b[::-1]:
        now -= 1
        tmp = a[id]
        while True:
            if tmp <= d:
                id += 1
                tmp += a[id]
            else:
                break
        ans = max(ans, now + id + 1)
else:
    a = a[:lena]
    ans = lena
    now = lena
    for d in a[::-1]:
        now -= 1
        tmp = b[id]
        while True:
            if tmp <= d:
                id += 1
                tmp += b[id]
            else:
                break
        ans = max(ans, now + id + 1)

print(ans)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
aes = list(map(int, input().split()))
bs = list(map(int, input().split()))
r_aes = [0]*n
for i in range(1,n):
    aes[i] += aes[i-1]
for i in range(1,m):
    bs[i] += bs[i-1]
cnt_a = 0
for i in range(n):
    if aes[i] > k:
        break
    cnt_a += 1
cnt_b = 0
res = cnt_a
#cnt = 5
while True:
    #print("cnt_a: "+str(cnt_a))
    #print("cnt_b: " + str(cnt_b))
    if cnt_b >= m or bs[cnt_b] > k:
        break
    if k-aes[cnt_a-1]>=bs[cnt_b]:
        cnt_b += 1
        res = max(res,cnt_a+cnt_b)
        continue
    cnt_a -= 1
    if cnt_a < 1:
        break
    #if cnt<= 0:
        #break
print(res)

Submission status: Wrong Answer

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

A.append(10**10)
B.append(10**10)

c=0

for i in range(1000):
    a = A[0]
    b = B[0]
    if a < b:
        K = K-a
        if K<0:
            break
        A = A[1:] 
        c = c+1
    else:
        K = K - b
        if K<0:
            break
        B = B[1:]
        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()))

i,j = 0,0

cnt = 0
time = 0

while((i<n and j<m) and (a[i]+time<=k or a[j]+time<=k)):
    if(a[i]<=b[j] and a[i]+time<k):
        time+=a[i]
        i+=1
    
    elif(b[j]<=a[i] and b[j]+time<k):
        time+=b[j]
        j+=1
    
    cnt+=1
    

while(i<n and a[i]+time<=k):
    time+=a[i]
    i+=1
    cnt+=1
    
while(j<m and b[j]+time<=k):
    time+=b[j]
    j+=1
    cnt+=1

print(cnt)

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

ans = 0
pile = 0

aq = deque(a)
bq = deque(b)

while(pile <= k):
    ans += 1
    if len(aq) == 0 and len(bq) == 0:
        break

    elif len(aq) == 0 and len(bq) != 0:
        #pop form b
        pile += bq.popleft()

    elif len(aq) != 0 and len(bq) == 0:
        #pop from a
        pile += aq.popleft()

    elif aq[0] > bq[0]:
        #pop form b
        pile += bq.popleft()

    else:
        #pop form a
        pile += aq.popleft()

print(ans-1)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3
import bisect
# from collections import Counter, deque, OrderedDict, defaultdict
# from copy import copy, deepcopy # pythonのみ．copyは1次元，deepcopyは多次元．
# from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
# from functools import reduce
# from heapq import heapify, heappop, heappush
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import statistics # Pythonのみ
# import string
import unittest
from io import StringIO
import sys
sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():

    n, m, k = map(int, input().split())
    A = [0]+list(map(int, input().split()))
    B = [0]+list(map(int, input().split()))

    from itertools import accumulate

    AA = [0] + A
    BB = [0]+B
    # 累積和を格納したリスト．A[l:r]の総和はB[r] - B[l]
    AA = list(accumulate(A))
    BB = list(accumulate(B))

    ans=0
    for i in range(n+1):
        s=AA[i]
        if s>=k: continue
        rem=k-s
        idx=bisect.bisect_right(BB,rem)-1
        ans=max(ans,i+idx)
    print(ans)
            


resolve()

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
i=0
j=0
time=0
ans=0
while i<=n-1 or j<=m-1:
  if i>n-1:
    if k>=time+b[j]:
      time+=b[j]
      j+=1
      ans+=1
    else:
      break
  elif j>m-1:
    if k>=time+a[i]:
      time+=a[i]
      i+=1
      ans+=1
    else:
      break
  else:
    if a[i]<=b[j] and k>=time+a[i]:
      time+=a[i]
      i+=1
      ans+=1
    elif a[i]>b[j] and k>=time+b[j]:
      time+=b[j]
      j+=1
      ans+=1
    else:
      break
print(ans)

Submission status: Wrong Answer

Solution code:
##C
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
##print(A+B)
C = A+B
##print(C)
i = 0
j = 0
goukei = 0
if K >= sum(C):
    print(N+M)
else:
    A = A+[10**9]
    B = B+[10**9]
    while goukei <= K: 
        if A[i] <= B[j]:
            goukei += A[i]
            i += 1
        else:
            goukei += B[j]
            j += 1
    print(i+j-1)

Submission status: Wrong Answer

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

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

init = (K, 0, 0)
memo = dict()
res = 0
q = deque()
q.append(init)
while q:
    deadline, ai, bi = q.popleft()
    memo[(ai, bi)] = deadline
    if ai < N and memo.get((ai+1,bi)) is None and deadline - A[ai] >= 0:
        q.append((deadline - A[ai], ai+1, bi))
    if bi < M and memo.get((ai, bi+1)) is None and deadline - B[bi] >= 0:
        q.append((deadline - B[bi], ai, bi+1))
    
print(res)

Submission status: Wrong Answer

Solution code:
from collections import deque

l1 = str(input()).split()

N = int(l1[0])
M = int(l1[1])
K = int(l1[2])

aq = deque([int(v) for v in str(input()).split()])
bq = deque([int(v) for v in str(input()).split()])

t = 0
count = 0
while len(aq) > 0 or len(bq) > 0:
    t = 0
    if len(bq) == 0:
        t += aq.popleft()
    elif len(aq) == 0:
        t += bq.popleft()
    elif aq[0] < bq[0]:
        t += aq.popleft()
    else:
        t += bq.popleft()

    if (K - t) < 0:
        break

    K -= t
    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()))

sumnum = 0
count = 0
flag = 0


while 1:
    if len(A) == 0 and len(B) == 0:
        break

    elif len(A) == 0:
        tmp = sumnum + B[0]
        flag = 1

    elif len(B) == 0:
        tmp = sumnum + A[0]

    elif A[0] < B[0]:
        tmp = sumnum + A[0]

    else:
        tmp = sumnum + B[0]
        flag = 1

    if tmp > K:
        break

    else:
        sumnum = tmp
        count = count + 1
        if flag == 0:
            A.pop(0)
        else:
            B.pop(0)
            flag = 0

print(count)

Submission status: Wrong Answer

Solution code:
import numpy as np
import scipy
import itertools

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

iter = [x for x in itertools.chain.from_iterable(itertools.zip_longest(A,B)) if x]
cnt =  0
sum = 0
print(iter)

for i in iter:
    sum += i
    if sum > K:
        break
    else:
        cnt +=1
print(cnt)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate

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

a_i = 0
b_i = 0
a_minutes = 0
b_minutes = 0
while True:
    if a_i == len(a) and b_i == len(b):
        break
    elif a_i == len(a):
        if b[b_i] + a_minutes > k:
            break
        b_minutes = b[b_i]
        b_i += 1
    elif b_i == len(b):
        if a[a_i] + b_minutes > k:
            break
        a_minutes = a[a_i]
        a_i += 1
    elif a[a_i] <= b[b_i] + a_minutes:
        if a[a_i] + b_minutes > k:
            break
        a_minutes = a[a_i]
        a_i += 1
    else:
        if b[b_i] + a_minutes > k:
            break
        b_minutes = b[b_i]
        b_i += 1

print(a_i + b_i)

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()))
AB = list()
ai = 0
bi = 0
time = 0
num = 0
leng = N + M
for _ in range(leng):
  if ai == len(A) and bi == len(B):
    break
  elif ai == len(A):
    AB.append(B[bi])
    bi += 1
  elif bi == len(B):
    AB.append(A[ai])
    ai += 1
  elif A[ai] < B[bi]:
    AB.append(A[ai])
    ai += 1
  else:
    AB.append(B[bi])
    bi += 1
for i in range(leng):
  time += AB[i]
  if time <= K:
    num += 1
  else:
    break
print(num)

Submission status: Wrong Answer

Solution code:
from collections import deque

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

a_q = deque()
b_q = deque(b_list)
ans = 0

for a in a_list:
    if k - a >=0:
        a_q.append(a)
        k -= a
        ans += 1
while True:
    if b_q:
        if k - b_q[0] >=0:
            k -= b_q.popleft()
            ans += 1
        else:
            break
    else:
        break
el_num = len(a_q)
final_ans = ans
while a_q and True:
    ans -= 1
    k += a_q.pop()
    while b_q and True:
        if b_q:
            if k - b_q[0] >=0:
                k -= b_q.popleft()
                ans += 1
            else:
                break
        else:
            break
    final_ans = max(final_ans, ans)
print(final_ans)

Submission status: Wrong Answer

Solution code:

N,M,K = map(int,input().split())
A_lis = list(map(int,input().split()))
B_lis = list(map(int,input().split()))





if A_lis[0]>B_lis[0]:
    status=B_lis[0]
elif A_lis[0]<B_lis[0]:
    status=A_lis[0]
else:
    status=A_lis[0]
    
    

count=0



for i in range(len(A_lis)+len(B_lis)):
    if K>status:
        if len(A_lis)>0 and len(B_lis)>0:
            if A_lis[0]<B_lis[0]:
                pd=A_lis.pop(0)
                status+=pd
                count+=1
            elif A_lis[0]>B_lis[0]:
                pd=B_lis.pop(0)
                status+=pd
                count+=1
            elif A_lis[0]==B_lis[0]:
                pd=A_lis.pop(0)
                status+=pd
                count+=1
        elif len(A_lis)==0 and len(B_lis)==0:
            s="うい"
        elif len(A_lis)==0:
            pd=B_lis.pop(0)
            status+=pd
            count+=1
        elif len(B_lis)==0:
            pd=A_lis.pop(0)
            status+=pd
            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()))
ans = 0

a_in = 0
b_in = 0

for _ in range(N+M):
    if len(A) == a_in:
        a = float('inf')
    else:
        a = A[a_in]

    if len(B) == b_in:
        b = float('inf')
    else:
        b = B[b_in]

    if a >= b and K >= b:
        ans += 1
        b_in += 1
        K -= b
    elif b > a and K >= a:
        ans += 1
        a_in += 1
        K -= a
    else:
        break
print(ans)

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

a_idx = 0
b_idx = 0
cnt = 0
while True:
  if a_idx < N and b_idx < M:
    if A_list[a_idx] >= B_list[b_idx]:
      K -= B_list[b_idx]
      b_idx += 1
      cnt += 1
    else:
      K -= A_list[a_idx]
      a_idx += 1
      cnt += 1
  elif a_idx == N and b_idx < M:
    K -= B_list[b_idx]
    b_idx += 1
    cnt += 1
  elif a_idx < N and b_idx == M:
    K -= A_list[a_idx]
    a_idx += 1
    cnt += 1
  else:
    break
  
  if K < 0:
    cnt -= 1
    break
print(cnt)

Submission status: Wrong Answer

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

a=N
b=M
count =0

while K != "sf":
    
    
    
    if a >0 and b > 0:
        if A[N-a] >= B[M-b]:
            count += 1
            K -= A[N-a]
            a -=1
            
        elif A[N-a] < B[M-b]:
            count += 1
            K -=  B[M-b]
            b -=1
       
    elif a>0 and b ==0:
        count += 1
        K -= A[N-a]
        a -=1
        
    
    elif b>0 and a ==0:
        count += 1
        K -= B[M-b]
        b -=1
        
    else:
        break
    if K < 0:
        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()))
a.append(999999999999)
b.append(999999999999)
i=0
j=0
time = 0
while time < k:
    if a[i] <= b[j] and a[i]+time <= k:
        time +=a[i]
        i+=1
    elif a[i] >= b[j] and b[j]+time <= k:
        time+=b[j]
        j+=1
    else:
        break
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()))
time = 0
count = 0
Anum = 0
Bnum = 0
judgea = 0
judgeb = 0
check = 0
while time<=K:
    if judgea == 2 and judgeb ==1:
        break
        print('break')
    
    if (A[Anum]>B[Bnum] and judgeb != 1)or judgea == 2:
        time += B[Bnum]
        
        if Bnum+1 >= len(B):
            judgeb = 1
        else:
            Bnum += 1
        count += 1
        check = 1
        
    if  (check != 1 and A[Anum]<=B[Bnum] and judgea != 2)or(check != 1 and judgeb == 1):
        time += A[Anum]
        
       
        if Anum+1 >= len(A):
            judgea = 2
        else:
            Anum += 1
        count += 1
        
    check = 0
if time>K:
    count-= 1

print(count)