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:
from collections import deque

N, M, K =[int(i) for i in input().split()]
An = [int(i) for i in input().split()]
Bn = [int(i) for i in input().split()]

#qa = deque(An)
#qb = deque(Bn)

max_val = 10**9
ans = 0

# 読める本がなくなるか、Kが0以下になるまでずっと本を読む
while True:
    if(K < 0):
        break
    # AかBどっちかの本を読む
    if(len(An) == 0 and len(Bn) == 0):
        break
    elif(len(An) == 0):
        K -= Bn[0]
        del Bn[0]
        ans += 1
    elif(len(Bn) == 0):
        K -= An[0]
        del An[0]
        ans += 1
    else:
        for i in range(min(len(An), len(Bn))):
            if(An[i] == Bn[i]):
                if(i+1 >= len(An)):
                    K -= Bn[i]
                    del Bn[:(i+1)]
                elif(i+1 >= len(Bn)):
                    K -= An[i]
                    del An[:(i+1)]
                else:
                    continue
            else:
                # Aのほうが小さいばあい
                if(An[i] < Bn[i]):
                    K -= An[i]
                    del An[:(i+1)]
                else:
                    K -= Bn[i]
                    del Bn[:(i+1)]
                if(K < 0):
                   break
                else:
                   ans += (i+1)
                   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()))
t_sum = 0
cnt = 0
flag = True

for _ in range(400000):
  if A == []:
    for _ in range(len(B)+1):
      if B == []:
        flag = False
        break
      t_sum += B[0]
      cnt += 1
      B = B[1:]
      if t_sum > K:
        cnt -= 1
        flag = False
        break
  if not flag:
    break
  if B == []:
    for _ in range(len(A)+1):
      if A == []:
        flag = False
        break
      t_sum += A[0]
      cnt += 1
      A = A[1:]
      if t_sum > K:
        cnt -= 1
        flag = False
        break
  if not flag:
    break
  if A[0] <= B[0]:
    t_sum += A[0]
    cnt += 1
    A = A[1:]
  else:
    t_sum += B[0]
    cnt += 1
    B = B[1:]
  if t_sum > K:
    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()))

ans = 0
remainTime = K

while remainTime >= 0:
  if not A and not B:
    ans += 1
    break
  elif not A:
    remainTime -= B.pop(0)
    ans += 1
  elif not B:
    remainTime -= A.pop(0)
    ans += 1
  else:
    if A[0] <= B[0]:
      remainTime -= A.pop(0)
      ans += 1
    else:
      remainTime -= B.pop(0)
      ans += 1
print(ans-1)

Submission status: Wrong Answer

Solution code:
from collections import deque
import copy
N, M, K = map(int, input().split())
A = deque(list(map(int, input().split())))
B = deque(list(map(int, input().split())))
counter = 0
ans = 0
a = A.popleft()
b = B.popleft()
while counter < K:
    ans += 1
    if a >= b:
        counter += b
        if not B:
            b = 0
            break
        b = B.popleft()
    else:
        counter += a
        if not A:
            a = 0
            break
        a = A.popleft()
if counter > K:
    print(ans - 1)
else:
    if a == 0:
        A = B
        a = b
    while counter < K:
        ans += 1
        counter += a
        if not A:
            if counter <= K:
                ans += 1
            break
        a = A.popleft()
    print(ans - 1)

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]

x = a.pop()
y = b.pop()
v = len(a)
w = len(b)
t = 0
ans = 0
while True:
    if k < t + min(x, y) or (x == 10 ** 9 + 1 and y == 10 ** 9 + 1):
        break
    if x == 0 or x >= y:
        t += y
        if w == 0:
            y = 10 ** 9 + 1
        else:
            y = b.pop()
            w -= 1
    elif y == 0 or x < y:
        t += x
        if v == 0:
            x = 10 **9 + 1
        else:
            x = a.pop()
            v -= 1
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
n, m, k = map(int, input().split())
s = list(map(int, input().split())) 
t = list(map(int, input().split())) 
time = 0
book = 0
for i in range(n + m + 2):
    if s != [] and t != []:
        if s[0] <= t[0]:
            if s[0] + time <= k:
                time += s[0]
                book += 1
                s.pop(0)
            else:
                print(book)
                sys.exit()
        else:
            if t[0] + time <= k:
                time += t[0]
                book += 1
                t.pop(0)
            else:
                print(book)
                sys.exit()
    if s == [] and t != []:
        if t[0] + time <= k:
            time += t[0]
            book += 1
            t.pop(0)
        else:
            print(book)
            sys.exit()
    if t == [] and s != []:
        if s[0] + time <= k:
            time += s[0]
            book += 1
            s.pop(0)
        else:
            print(book)
            sys.exit()   
    if t == [] and s == []:
        print(book)
        sys.exit()

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
N, M, K = map(int, input().split())
As = [0] + list(map(int, input().split()))
Bs = [0] + list(map(int, input().split()))
csum_A = list(accumulate(As))
csum_B = list(accumulate(Bs))

ok = 0
ng = N + M + 2
while ng - ok > 1:
    mid = (ng + ok) // 2
    min_time = 10 ** 9
    for t in range(max(0, mid-M), min(mid, N+1)):
        min_time = min(min_time, csum_A[t] + csum_B[mid - t])
    
    if K >= min_time:
        ok = mid
    else:
        ng = mid

print(ok)

Submission status: Wrong Answer

Solution code:
line = input().strip().split()
n = int(line[0])
m = int(line[1])
k = int(line[2])

line = input().strip().split()
a = []
for i in line:
    a.append(int(i))

line = input().strip().split()
b = []
for i in line:
    b.append(int(i))

sum_a = [0]
sum = 0
for i in range(n):
    sum += a[i]
    sum_a.append(sum)

sum_b = [0]
sum = 0
for i in range(m):
    sum += b[i]
    sum_b.append(sum)

sum_a2 = [i for i in sum_a if i <= k]
sum_b2 = [i for i in sum_b if i <= k]

tmp = [0, 0]
for i in range(len(sum_a2)):
    for j in range(len(sum_b2)):
        if sum_a2[i] + sum_b2[j] <= k:
            tmp = [i, j]

if tmp == [0, 0]:
    print(0)
else:
    print(tmp[0] + tmp[1])

Submission status: Wrong Answer

Solution code:
def main():
  N,M,K=input().split()
  a=[int(x) for x in input().split()]
  b=[int(x) for x in input().split()]
  ai=0
  bi=0
  cnt=0
  while cnt<int(K):
    if ai>=int(N) and bi>=int(M):
      return ai+bi
    elif ai>=int(N):
      cnt+=b[bi]
      bi+=1
    elif bi>=int(M):
      cnt+=a[ai]
      ai+=1
    elif a[ai]<=b[bi]:
      cnt+=a[ai]
      ai+=1
    else:
      cnt+=b[bi]
      bi+=1
  return ai+bi-1

if __name__=='__main__':
  print(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
count = 0
while time <= K:
    if len(A) == 0 and len(B) == 0:
        break
    elif len(A) == 0:
        time += B.pop(0)
        if time <= K:
            count += 1

    elif len(B) == 0:
        time += A.pop(0)
        if time <= K:
            count += 1

    else:
        if A[0] <= B[0]:
            time += A.pop(0)
            if time <= K:
                count += 1
        else:
            time += B.pop(0)
            if time <= K:
                count += 1
print(count)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
Ai=[int(i) for i in input().split()]
Bi=[int(i) for i in input().split()]
nbook=0
tbook=0
na=0; nb=0
while tbook <K:
    if((na<len(Ai)) and (nb<len(Bi))):
        if(Ai[na]<=Bi[nb]):
            if(tbook+Ai[na]<=K):
                nbook+=1;  tbook+=Ai[na];na+=1;
            else:
              break;
        else:
            if(tbook+Bi[nb]<=K):
                nbook+=1;tbook+=Bi[nb]; nb+=1; 
            else:
              break;
    elif( (na>=len(Ai)) and (nb<len(Bi))):
        if(tbook+Bi[nb]<=K):
            nbook+=1;tbook+=Bi[nb]; nb+=1;
        else:
            break;  
    elif( (na<len(Ai)) and (nb>=len(Bi))):
        if(tbook+Ai[na]<=K):
            nbook+=1;  tbook+=Ai[na];na+=1;
        else:
            break;
     
    else:
        break;      
print(nbook)

Submission status: Wrong Answer

Solution code:
n_m_k = input().split()
n = int(n_m_k[0])
m = int(n_m_k[1])
k = int(n_m_k[2])

a_str_list = input().split()
a_int_list = [int(x) for x in a_str_list]

b_str_list = input().split()
b_int_list = [int(x) for x in b_str_list]

sum_t = 0
cnt_a = 0
cnt_b = 0

len_a = len(a_int_list)
len_b = len(b_int_list)
while(1):
    if((cnt_a != len_a) and (cnt_b != len_b)):
        if(a_int_list[cnt_a] < b_int_list[cnt_b]):
            sum_t += a_int_list[cnt_a]
            if(sum_t < k):
                cnt_a += 1
            else:
                break
        else:
            sum_t += b_int_list[cnt_b]
            if(sum_t < k):
                cnt_b += 1
            else:
                break
    elif(cnt_a < len_a):
        sum_t += a_int_list[cnt_a]
        if(sum_t < k):
            cnt_a += 1
        else:
            break
    elif(cnt_b < len_b):
        sum_t += b_int_list[cnt_b]
        if(sum_t < k):
            cnt_b += 1
        else:
            break
    else:
        break

print(cnt_a + cnt_b)

Submission status: Wrong Answer

Solution code:
from collections import deque

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

ans = 0
for _ in range(n+m):
    if len(a) + len(b) == 0:
        break
    if len(a) == 0:
        if b[0] > k:
            break
        k -= b.popleft()
        ans += 1
    elif len(b) == 0:
        if a[0] > k:
            break
        k -= a.popleft()
        ans += 1
    elif a[0] <= b[0]:
        if a[0] > k:
            break
        k -= a.popleft()
        ans += 1
    else:
        if b[0] > k:
            break
        k -= b.popleft()
        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()))

ai = 0
bi = 0
ans = 0

for _ in range(n+m):
    if ai >= n and bi >= m:
        break
    if ai < n:
        a = A[ai]
    else: 
        a = 10e10
    if bi < m:
        b = B[bi]
    else:
        b = 10e10
    if a > b:
        k -= b
        bi += 1
    else:
        k -= a
        ai += 1
    if k < 0:
        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()))
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-i
    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

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

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

i = 0
j = 0
h = 0
dp = [-1] * 410000
dp[0] = 0
while dp[h] <= K:
    h += 1
    #print(h)
    if i < lA:
        dp[h] = dp[h-1] + A[i]
        #print(dp[h])
    else:
        dp[h] = 10 ** 18
    if j < lB:
        if dp[h] > dp[h-1] + B[j]:
            dp[h] = dp[h-1] + B[j]
            #print(dp[h])
            j += 1
        else:
            i += 1
    if i >= lA and j >= lB:
        print(lA + lB)
        sys.exit(0)

print(h-1)

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 = [0,BList[0]]
for i in range(1,M+1):
  a = BSList[-1] + BList[i]
  BSList.append(a)  
  
ans = 0
for i in range(M+1):
  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)
  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()))
A.append(10**12)
B.append(10**12)

sig_a = 0
sig_b = 0
ans = 0
for i in range(N+M):
  if A[sig_a] >= B[sig_b]:
    ans += B[sig_b]
    sig_b += 1
  else:
    ans += A[sig_a]
    sig_a += 1
  if ans > K:
    print(i)
    break
    
if ans <= K:
  print(N+M)

Submission status: Wrong Answer

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

time = 0
count = 0
while len(a) > 0 or len(b) > 0:
    if len(a) ==  0:
        book_b = b.popleft()
        time += book_b
        count += 1
    elif len(b) == 0:
        book_a = a.popleft()
        time += book_a
        count+= 1
    elif a[0] > b[0]:
        book_b = b.popleft()
        time += book_b
        count += 1
    else:
        book_a = a.popleft()
        time += book_a
        count += 1
    if time > k:
        count -= 1
        break
    
print(count)

Submission status: Wrong Answer

Solution code:
A,B,Time=[int(x) for x in input().split()]
ArrayA=[int(x) for x in input().split()]+[10**10]
ArrayB=[int(x) for x in input().split()]+[10**10]
TotalTime=0
x,y=0,0
while TotalTime<=Time:
	if ArrayA[x]>ArrayB[y]:
		TotalTime+=ArrayB[y]
		y+=1
		#print(x,y)
		continue
	if ArrayA[x]<ArrayB[y]:
		TotalTime+=ArrayA[x]
		x+=1
		#print(x,y)
		continue
	if x+y==len(ArrayA)+len(ArrayB)-2:
		print(x+y)
		exit()
	if x+y==0:
		print("0")
		exit()
print(x+y-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()))
books = 0
cost = 0
for i in range(N+M):
    if cost > K:
        books -= 1
        break
        
    if len(B) == 0:
        cost += A.pop(0)
        books += 1
    elif len(A) == 0 or A[0] >= B[0]:
        cost += B.pop(0)
        books += 1
    else:
        cost += A.pop(0)
        books += 1
if cost > K:
    print(books-1)
    
elif books <= 0:
    print(0)
else:
    print(books)

Submission status: Wrong Answer

Solution code:
import sys
from pprint import pprint
import bisect

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

ans = 0
max_read = N + M

S_a = [0 for _ in range(N+1)]
S_b = [0 for _ in range(M+1)]
for i in range(N):
    S_a[i+1] = A[i] + S_a[i]
for i in range(M):
    S_b[i+1] = B[i] + S_b[i]
# print(S_a)
# print(S_b)

ans = 0
for i in range(N):
    # A を i冊読んだ時、その時よめるBの最大値を二分探索
    sum_t = S_a[i+1] - S_a[0]
    if sum_t > K:
        continue
    # print(K - sum_t)
    b_index = bisect.bisect_right(S_b, K - sum_t)
    # print(i, b_index)
    ans = max(ans, i + b_index)
    
print(ans)

Submission status: Wrong Answer

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

from collections import deque
a=deque(a)
b=deque(b)

cnt=0
ans=0
while cnt<=k:
    if (not a) and (not b):
        ans+=1
        break
    elif a and b:
        if a[0]>=b[0]:
            cnt+=b.popleft()
            ans+=1
        elif a[0]<b[0]:
            cnt+=a.popleft()
            ans+=1
    elif a:
        cnt+=a.popleft()
        ans+=1
    elif b:
        cnt+=b.popleft()
        ans+=1

    # print(cnt, a, b, ans)

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())))
c=0
while k>=0:
  if not(a==deque([]) or b==deque([])) and a[0]<=b[0]:
    e=a.popleft()

    k=k-e
    c+=1

  elif not(a==deque([]) or b==deque([])) and a[0]>b[0]:
    e=b.popleft()

    k=k-e
    c+=1

  elif a==deque([]) and b!=deque([]):
    e=b.popleft()

    k=k-e
    c+=1
  elif a!=deque([]) and b==deque([]):
    e=a.popleft()
 
    k=k-e
    c+=1    
  elif a==deque([]) and b==deque([]):
    break

if k>=0:
  print(c)
else:
  print(c-1)

Submission status: Wrong Answer

Solution code:
import bisect as bc

N,M,K = map(int,input().split())
A = [0]*(N+1)
B = [0]*(M+1)
A[1:] = list(map(int,input().split()))
B[1:] = list(map(int,input().split()))
A.append(10**9+10)
B.append(10**9+10)

A_S = [0]*(N+2)
B_S = [0]*(M+2)

for i in range(1,N+2):
    A_S[i] = A_S[i-1]+A[i]
for i in range(1,M+2):
    B_S[i] = B_S[i-1]+B[i]

ans = 0
for i in range(N+1):
    tmp_K = K-A_S[i]
    if tmp_K > 0:
        j = bc.bisect_right(B_S,tmp_K) - 1
        ans = max(i+j,ans)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

INF = 1 << 60
A = [INF] + A[::-1]
B = [INF] + B[::-1]

n = 0
while True:
    if A[-1] > B[-1]:
        A, B = B, A
    x = A.pop()
    if K >= x:
        n += 1
        K -= x
    else:
        break

print(n)

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
judge = 0
while time<=K:
    if Anum>=len(A) and Bnum>=len(B):
        break
    
    if A[Anum]>=B[Bnum] or judge == 2:
        time += B[Bnum]
        
        if Bnum+1 >= len(B):
            judge = 1
        else:
            Bnum += 1
        count += 1
    elif A[Anum]<=B[Bnum] or judge == 1:
        time += A[Anum]
       
        if Anum+1 >= len(A):
            judge = 2
        else:
            Anum += 1
        count += 1
if time>K:
    count-= 1

print(count)

Submission status: Wrong Answer

Solution code:
from collections import deque
def main():
    N, M, K = map(int, input().split())
    A = [int(a) for a in input().split()]
    B = [int(b) for b in input().split()]
    A = deque(A)
    B = deque(B)

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

    ans = tot = 0

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

        if a < b:
            if tot + a <= K:
                ans += 1
                tot += A.popleft()
            else:
                break

        elif a > b:
            if tot + b <= K:
                ans += 1
                tot += B.popleft()
            else:
                break

        else:
            if tot + a <= K:
                ans += 1
                tot += A.popleft()
            else:
                break

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

A_ruiseki = [A[0]]
for i in range(1, n):
    if A_ruiseki[i-1]+A[i] <= k :
        A_ruiseki.append(A_ruiseki[i-1]+A[i])
    else:
        break
print(A_ruiseki)
ans = 0

for i in range(len(A_ruiseki)):
    time = A_ruiseki[i]
    if time > k:
        continue
    cnt_b = 0
    while cnt_b < m:
        if time + B[cnt_b] <= k:
            time += B[cnt_b]
            cnt_b += 1
        else:
            break

    ans = max(ans, (i+1) + cnt_b)

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

A_array = np.array(list(map(int, input().split())))

B_array = np.array(list(map(int, input().split())))

time = 0
count = 0

while True:
    
    if len(A_array) == 0 and len(B_array) != 0:
        time += B_array[0]  
        B_array = np.delete(B_array, 0)
    elif len(B_array) == 0 and len(A_array) != 0:
        time += A_array[0] 
        A_array = np.delete(A_array, 0)
    elif A_array[0] ==  B_array[0]:
        time += A_array[0]
        A_array = np.delete(A_array, 0)
    elif A_array[0] <  B_array[0]:  
        time += A_array[0]
        A_array = np.delete(A_array, 0)
    else:
        time += B_array[0]
        B_array = np.delete(B_array, 0)
    
    if time > K:
        break
    
    count += 1

    if len(A_array) == 0 and len(B_array) == 0:
        break

print(count)

Submission status: Wrong Answer

Solution code:
from collections import deque

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

    sumA = 0
    sumB = 0

    tmp = 0

    dA = deque(A)
    dB = deque(B)

    dsA = deque()
    dsB = deque()

    while dA:
        tmp = dA.popleft()
        if sumA + tmp < K:
            dsA.append(tmp)
            sumA += tmp
        else:
            break
    
    while dB:
        tmp = dB.popleft()
        if sumB + tmp < K:
            dsB.append(tmp)
            sumB += tmp
        else:
            break

    sumall = sumA + sumB
    lenall = len(dsA) + len(dsB)
    Atmp = 0
    Btmp = 0

    while sumall > K:
        print(dsA, dsB, sumall)
        if Atmp == 0:
            Atmp = dsA.pop()
        if Btmp == 0:
            Btmp = dsB.pop()
        print(Atmp, Btmp)
        if Atmp >= Btmp:
            sumall -= Atmp
            lenall -= 1
            Atmp = 0
        else:
            sumall -= Btmp
            lenall -= 1
            Btmp = 0

    print(lenall)
                
solve()

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_counter = 0
a_all_flag = -1
b_counter = 0
b_all_flag = -1
total_time = 0
total_book = 0

for cnt in range(n+m):
    if a[a_counter] <= b[b_counter] and a_all_flag != 1:
        if k - a[a_counter] >= 0:
            if a_counter+1 < n:
                a_counter += 1
            else:
                a_all_flag = 1
            total_book += 1
        else:
            break
    elif a[a_counter] > b[b_counter] and b_all_flag != 1:
        if k - b[b_counter] >= 0:
            if b_counter+1 < m:
                b_counter += 1
            else:
                b_all_flag = 1
            total_book += 1
        else:
            break
    elif a_all_flag != 1 and b_all_flag == 1:
        if k - a[a_counter] >= 0:
            if a_counter+1 < n:
                a_counter += 1
            else:
                a_all_flag = 1
            total_book += 1
        else:
            break
    elif a_all_flag == 1 and b_all_flag != 1:
        if k - b[b_counter] >= 0:
            if b_counter+1 < m:
                b_counter += 1
            else:
                b_all_flag = 1
            total_book += 1
        else:
            break

print(total_book)

Submission status: Wrong Answer

Solution code:
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
i=0
j=0
t=0
b=0
A.append(1000000001)
B.append(1000000001)
while t < K:
    if A[i]>B[j]:
        t+=B[j]
        j+=1
    else:
        t+=A[i]
        i+=1
print(i+j)

Submission status: Wrong Answer

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

from collections import deque
a = deque(a)
b = deque(b)
# print(len(a),len(b))
c = 0
ans = 0
while (len(a)>0 or len(b)>0)&(k>0):
    if len(a)>0 and len(b)>0: 
        if (a[0]<b[0])&(a[0]<=k):
                k-=a[0]
                a.pop()
                ans +=1
                # print("a")
        elif (a[0]>=b[0])&(b[0]<=k):
                k-=b[0]
                b.pop()
                ans+=1

        else:
                break
    elif len(a)==0 :
        if b[0]>k:
            break
        else:
            k-=b[0]
            b.pop()
            
            ans +=1
            if len(b)==0:
                break

    elif len(b)==0 :
        if a[0]>k:
            break
        else:
            k-=a[0]
            a.pop()
            ans +=1
            if len(a)==0:
                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()))

sumA = [A[0]]
sumB = [B[0]]

for i in range(N-1):
    sumA.append(sumA[-1] + A[i+1])

for i in range(M-1):
    sumB.append(sumB[-1] + B[i+1])

ans = 0

for i in range(N):
    for j in range(M):
        if (sumA[i] + sumB[j] <= K):
            ans = max(ans, i+1+j+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()))

cnt = 0
while (K >= 0):
    if len(A) > 0:
        if A[0] <= B[0]:
            K = K - A[0]
            A.pop()
        else:
            if len(B) > 0 :
                K = K - B[0]
            else:
                break

    else:
        if len(B) > 0:
            K = K - B[0]
            B.pop()
        else:
            if len(A) > 0:
                A.pop()
                K = K - A[0]
            else:
                break

    if K <= 0:
        break

    cnt = cnt + 1

print(cnt)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    a, b = A[::-1], B[::-1]
    ans = 0
    while 1:
        if a and b:
            if a[-1] < b[-1]:
                if K < a[-1]:
                    break
                else:
                    K -= a.pop()
                    ans += 1
            else:
                if K < b[-1]:
                    break
                else:
                    K -= b.pop()
                    ans += 1
        elif a:
            if K < a[-1]:
                break
            else:
                K -= a.pop()
                ans += 1
        elif b:
            if K < b[-1]:
                break
            else:
                K -= b.pop()
                ans += 1
        else:
            break
    print(ans)


main()

Submission status: Wrong Answer

Solution code:
N,M,K=map(int,input().split())
A=map(int,input().split())
A=list(A)
B=map(int,input().split())
B=list(B)
time=int(0)
book=int(0)
#flaga=int(0)
#flagb=int(0)
#print(A)
#print(A[1:])
while time<K and len(A)>0 and len(B)>0:
    if A[0]<=B[0]:
        time += A[0]
        book += 1
        if len(A)==1:
            A=[]
            break
        A=A[1:]
    else:
        time += B[0]
        book +=1
        if len(B)==1:
            B=[]
            break
        B=B[1:]
'''
        if time >=K:
            flaga=int(1)
            ansa=A[0]
        A=A[1:]
'''
'''
        if time >=K:
            flagb=int(1)
            ansb=B[0]
'''

if time<K and len(A)==0:
    while time<K and len(B)>0:
        time+=B[0]
        book+=1
        if len(B)==1:
            B=[]
            break
        '''
        if time >=K:
            flagb=int(1)
            ansb=B[0]
        '''
        B=B[1:]
elif time<K and len(B)==0:
    while time<K and len(A)>0:
        time+=A[0]
        book+=1
        if len(A)==1:
            A=[]
            break
        '''
        if time >=K:
            flaga=int(1)
            ansa=A[0]
        '''
        A=A[1:]
'''
if flaga ==int(1):
    time -= ansa
elif flagb ==int(1):
    time -= ansb
'''
if len(A)==0 and len(B)==0:
    print(book)
else:
    print(book-1)

Submission status: Wrong Answer

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

count = 0
timecount = 0

while timecount <= K:
    if A == [] and B == []:
        break
    if timecount > K:
        break
    if A and B:
        timecount += min(A[0], B[0])
        if timecount > K:
            break
        if min(A[0], B[0]) == A[0]:
            A.pop(0)
        else:
            B.pop(0)
        count += 1
    elif A == []:
        timecount += B[0]
        if B != []:
            B.pop(0)
        if timecount > K:
            break
        count += 1
    elif B == []:
        timecount += A[0]
        if A != []:
            A.pop(0)
        if timecount > K:
            break
        count += 1

print(count)