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:
N, M, K = map(int,input().split())
A = list(map(int,input().split()))	
B = list(map(int,input().split()))	

book_count = 0
time_count = 0
while time_count <= K:
    book_count += 1
    if len(A) > 0 and len(B) > 0:
        if A[0] > B[0]:
            time_count += B[0]
            B.pop(0)
        else:
            time_count += A[0]
            A.pop(0)
    elif len(A) == 0 and len(B) > 0:
        time_count += B[0]
    elif len(A) > 0 and len(B) == 0:
        time_count += A[0]

if book_count < N + M:
    print(book_count-1)
else:
    print(book_count)

Submission status: Wrong Answer

Solution code:
n, m, k=map(int, input().split())
a=list(map(int, input().split()))+[10**10]*100
b=list(map(int, input().split()))+[10**10]*100

loop=max(n, m)
i=0
j=0
T=0
ans=0

for t in range(2*loop):
    if a[i]>=b[j]:
        T+=b[j]
        if T<=k:
            ans+=1
            j+=1
        else:
            print(ans)
            exit()
    elif b[j]>a[i]:
        T+=a[i]
        if T<=k:
            ans+=1
            i+=1
        else:
            print(ans)
            exit()
    
    elif i==n-1:
        T+=b[j]
        if T<=k:
            ans+=1
            j+=1
        else:
            print(ans)
            exit()
    
    elif j==m-1:
        T+=a[i]
        if T<=k:
            ans+=1
            i+=1
        else:
            print(ans)
            exit()

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

time = 0
count = 0

a = deque(a)
b = deque(b)

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

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

t = 0
ans = 0
i = 0
j = 0
while t < k:
    if i < n and j < m:
        if a[i] < b[j]:
            if t + a[i] <= k:
                t += a[i]
                i += 1
            else:
                break
        else:
            if t + b[j] <= k:
                t += b[j]
                j += 1
            else:
                break
    elif i < n:
        if t + a[i] <= k:
            t += a[i]
            i += 1
        else:
            break
    elif j < m:
        if t + b[j] <= k:
            t += b[j]
            j += 1
        else:
            break
    ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
INF = 10**10
N,M,K = map(int,input().split())
A = list(map(int,input().split()))+[INF]
B = list(map(int,input().split()))+[INF]
C = deque(A)
D = deque(B)
ans = 0
tmp = 0
a = C.popleft()
b = D.popleft()
while True:
    if a<b:
        if tmp+a>K:
            break
        tmp += a
        ans += 1
        a = C.popleft()
    else:
        if tmp+b>K:
            break
        tmp += b
        ans += 1
        b = D.popleft()
C = deque(A)
D = deque(B)
ans1 = 0
tmp = 0
a = C.popleft()
b = D.popleft()
while True:
    if a<=b:
        if tmp+a>K:
            break
        tmp += a
        ans1 += 1
        a = C.popleft()
    else:
        if tmp+b>K:
            break
        tmp += b
        ans1 += 1
        b = D.popleft()
print(max(ans,ans1))

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.extend(b)
a = sorted(a)
c = [a[0]]
for i in range(1, len(a)):
    c.append(c[i-1] + a[i])

cnt = 0
for i in range(len(c)):
    if c[i] <= k:
        cnt += 1
    else:
        break
print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,m,k = list(map(int,input().split()))
a = list(map(int,input().split()))[::-1]
b = list(map(int,input().split()))[::-1]
cnt_book=0
cnt_time=0

while cnt_time<k:
  if not a:
    cnt_time+=b.pop()
  elif not b:
    cnt_time+=a.pop()
  elif a[-1]>=b[-1]:
    cnt_time+=b.pop()
  else:
    cnt_time+=a.pop()

  if cnt_time>k:
    break    
  cnt_book+=1
#  print(a,b)
  
  if not a and not b:
    break

print(cnt_book)

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

while(True):
    if len(a) > 0 and len(b) > 0:
        if a[0] > b[0]:
            tmp = b.pop(0)
            k -= tmp
        else:
            tmp = a.pop(0)
            k -= tmp
    elif len(a) == 0 and len(b) > 0:
        tmp = b.pop(0)
        k -= tmp
    elif len(b) == 0 and len(a) > 0:
        tmp = a.pop(0)
        k -= tmp
    else:
        break
    if k < 0:
        break
    count += 1

print(count)

Submission status: Wrong Answer

Solution code:
#!python3.8
# -*- coding: utf-8 -*-
# abc172/abc172_c
import sys
from collections import deque

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    N, M, K = i2nn()
    A = deque(i2nn())
    B = deque(i2nn())
    t = 0
    n = 0
    while True:
        if len(A) and len(B):
            if A[0] < B[0]:
                u = A.popleft()
            else:
                u = B.popleft()
            if t + u > K:
                break
            t += u
            n += 1
        elif len(A):
            u = A.popleft()
            if t + u > K:
                break
            t += u
            n += 1
        elif len(B):
            u = B.popleft()
            if t + u > K:
                break
            t += u
            n += 1
        else:
            break
        
    print(n)
    return

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

if N <= M:
    n = M
else:
    n = N
    
count = 0

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

    try:
        if B[i] <= K:
            K = K - B[i]
            count += 1
        else:
            break
    except:
        pass
    
print(count)

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

i, j = 0, 0
readed = 0
count = 0

while True:
    if i >= n:
        if j >= m:
            break
        else:
            readed += b[j]
            j += 1
    elif j >= m:
        readed += a[i]
        i += 1
    elif a[i] < b[j]:
        readed += a[i]
        i += 1
    elif a[i] == b[j]:
        if i+1 >= n:
            if j+1 >= m:
                readed += a[i]
                i += 1
            else:
                readed += b[j]
                j += 1
        else:
            if j+1 >= m:
                readed += a[i]
                i += 1
            else:
                if a[i+1] <= b[j+1]:
                    readed += a[i]
                    i += 1
                else:
                    readed += b[j]
                    j += 1
    else:
        readed += b[j]
        j += 1
    if readed > k:
        break
    count += 1
print(count)

Submission status: Wrong Answer

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

# a_li = [0] + a_li
# b_li = [0] + b_li

time = 0
ans = 0

for i in range(len(a_li)):
    for j in range(len(b_li)):
        time = sum(a_li[:i+1]) + sum(b_li[:j+1])
        if time <= k:
            ans = max(ans, i+j+2)
            
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
N,M,L = map(int,input().split())
A = deque(map(int,input().split()))
B = deque(map(int,input().split()))
cnt = 0
while True:
    if L <= 0:
        cnt -= 1
        break
    else:
        if len(A) != 0 and len(B) != 0:
            if A[0] < B[0]:
                tmp = A.popleft()
            else:
                tmp = B.popleft()
        elif len(A) != 0 and len(B) == 0:
            tmp = A.popleft()
        elif len(A) == 0 and len(B) != 0:
            tmp = B.popleft()
        else:
            break
        L -= tmp
        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()))

ans = 0
total = 0
idx = -1

for i in range(N):
  t = total + A[i]
  if t > K:
    break
  total = t
  ans += 1
  idx = i

for j in range(M):
  t = total + B[j]
  if t > K:
    # print(idx)
    for k in range(idx, -1, -1):
      t -= A[k]
      if t <= K:
        total = t
        ans -= (idx - k - 1)
        idx = k - 1
  else:
    total = t
    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() ) )

i = 0
j = 0
time = 0
read = 0

while True:
    if i == n and j == m:
        break
    elif i == n:
        if time + b[ j ] > k:
            break
        else:
            time += b[ j ]
            read += 1
            j += 1
    elif j == m:
        if time + a[ i ] > k:
            break
        else:
            time += a[ i ]
            read += 1
            i += 1
    elif a[ i ] < b[ j ]:
        if time + a[ i ] > k:
            break
        else:
            time += a[ i ]
            read += 1
            i += 1
    else:
        if time + b[ j ] > k:
            break
        else:
            time += b[ j ]
            read += 1
            j += 1
    
print( read )

Submission status: Wrong Answer

Solution code:
NMK=input().split(" ")
N=int(NMK[0])
M=int(NMK[1])
K=int(NMK[2])

def list2int(List):
    out=[]
    for i in range(len(List)):
        out.append(int(List[i]))
    return out

A=list2int(input().split(" "))
B=list2int(input().split(" "))

time=0
A_idx=0
B_idx=0
cnt=0
while(True):
    if(A_idx<len(A) and B_idx<len(B)):
        if(A[A_idx]<B[B_idx]):
            time+=A[A_idx]
            A_idx+=1
        elif(A[A_idx]==B[B_idx]):
            flag=""
            while(len(flag)<0):
                if(A_idx+1<len(A) and B_idx+1<len(B)):
                    if(A[A_idx+1]<B[B_idx]):
                        flag=="A"
                        break
                    elif(B[B_idx+1]<B[B_idx]):
                        flag=="B"
                        break
                    elif(A[A_idx]==B[B_idx]):
                        continue
            if(flag=="A"):
                time+=A[A_idx]
                A_idx+=1
            else:
                time+=B[B_idx]
                B_idx+=1
        else:
            time+=B[B_idx]
            B_idx+=1
    elif(A_idx>=len(A) and B_idx<len(B)):
        time+=B[B_idx]
        B_idx+=1
    elif(B_idx>=len(B) and A_idx<len(A)):
        time+=A[A_idx]
        A_idx+=1
    else:
        break
    if(time>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()))

counter = 0
ans = 0

for i in range(n):
  for j in range(m):
    if sum(A[:i+1])+sum(B[:j+1])<=k:
      ans = max(ans, i+1+j+1)
    else:
      break
      
print(ans)

Submission status: Wrong Answer

Solution code:
import math
from collections import Counter

# N = int(input()) # 1行, 単数
# arg = list(map(int, input().split())) # 1行, 配列
# D = Counter(arg) # 出現数カウント

# print('Yes')
# print('No')
# print()

# while True:
  # try:
    # listA=list(map(int,input().split()))
    # listA.append(list(map(int,input().split())))
  # except:
    # break;

N,M,K = list(map(int, input().split())) # 1行, 配列

A = list(map(int, input().split())) # 1行, 配列
B = list(map(int, input().split())) # 1行, 配列

ans = 0
now = 0
ai = 0
bi = 0
while True:
  if len(A) == ai  and len(B) == bi :
    break
  if len(A) == ai :
    now = now + B[bi]
    bi = bi + 1
  elif len(B) == bi :
      now = now + A[ai]
      ai = ai + 1
  elif len(A) > ai  and len(B) > bi :
    if A[0] > B[0]:
      now = now + B[bi]
      bi = bi +1
    else:
      now = now + A[ai]
      ai = ai + 1
  ans = ans + 1

  if now > K:
    ans = ans - 1
    break;
  elif now == K:
    break;

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
input = sys.stdin.buffer.readline


#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()

#import numpy as np
import bisect

def main():
	n,m,k=MI()
	A=LI()
	B=LI()

	for i in range(1,n):
		A[i]+=A[i-1]
	for j in range(1,m):
		B[j]+=B[j-1]
	#print(A,B)

	ans=0

	for i in range(n):
		if k>=A[i]:
			kk=k-A[i]
			j=bisect.bisect_right(B,kk)
			#print(kk,i,j)
			ans=max(ans,i+j+1)
		else:
			break

	print(ans)










if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
n, m, k = input().split()
n, m, k = int(n), int(m), int(k)
a = input().split()
b = input().split()
a = [int(x) for x in a]
b = [int(x) for x in b]

c = a+b

c.sort()


total = 0
i = 0
for i in range(0, len(c)):
    if total > k:
        break
    total += c[i]
    if total > k:
        i = i-1
        break


print(i+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()))
lim = max(n, m)
sum = 0
num = 0

for i in range(lim):
    if i <= min(n-1, m-1):
        if (sum + a[i]) <= k:
            sum += a[i]
            num += 1
            if sum == k :
                break
        elif sum + b[i] > k:
            break
        if (sum + b[i]) <= k:
            sum += b[i]
            num += 1
            if sum == k:
                break
        else:
            break
    else:
        if lim == n:
            if (sum + a[i]) <= k:
                sum += a[i]
                num += 1
                if sum == k:
                    break
            else:
                break
        elif lim == m:
            if sum + b[i] <= k:
                sum += b[i]
                num += 1
                if sum == k:
                    break
            else:
                break

print(num)

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

total = 0
cnt = 0

while total < K:
    cnt += 1
    if A == []:
        total += B.pop(0)
    elif B == []:
        total += A.pop(0)
    elif A[0] > B[0]:
        total += A.pop(0)
    else:
        total += B.pop(0)

print(cnt)

Submission status: Wrong Answer

Solution code:
# import sys
N, M, K = map(int, input().split())
A = [0] + list(map(int, input().split()))
B = [0] + list(map(int, input().split()))
sum_t = 0
cumsumA = [0]
cumsumB = [0]
ansA = N
ansB = M
tmp = 0
for i in range(1, N+1):
    tmp = tmp + A[i]
    if tmp > K:
        ansA = i-1
        break
    cumsumA += [tmp]
tmp = 0
for i in range(1, M+1):
    tmp = tmp + B[i]
    if tmp > K:
        ansB = i-1
        break
    cumsumB += [tmp]

ans_t = cumsumA[ansA] + cumsumB[ansB]
ans = ansA + ansB
while K < ans_t:
    ai, bi = A[ansA], B[ansB]
    if ai >= bi:
        ans_t -= ai
        ans -= 1
        ansA -= 1
    else:
        ans_t -= bi
        ans -= 1
        ansB -= 1
print(ans)
# print(ansA, ansB)

Submission status: Wrong Answer

Solution code:
import math  # noqa: F401
from collections import deque
from typing import Dict, List, Optional, Tuple, Union  # noqa: F401


def main(N: int, M: int, K: int, A, B):
    A = deque(A)
    B = deque(B)

    t = 0
    ans = 0

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

    while t <= K:
        if a < b:
            t += a
            if A:
                a = A.popleft()
            else:
                a = 10 ** 9 + 1
        else:
            t += b
            if B:
                b = B.popleft()
            else:
                b = 10 ** 9 + 1

        ans += 1

    if t > K:
        ans -= 1

    print(ans)


if __name__ == "__main__":
    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    main(N, M, K, A, B)

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 True:
    if len(A) == 0 and len(B) == 0:
        break
    
    if len(A) == 0:
        book = B[0]
    elif len(B) == 0:
        book = A[0]
    else:
        book = min(A[0], B[0])
    if time + book <= K:
        time += book
        count += 1
        if len(A) == 0:
            del B[0]
        elif len(B) == 0:
            del A[0]
        else:
            if A[0] <= B[0]:
                del A[0]
            else:
                del B[0]
    else:
        break

print(count)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)

from collections import deque

INF = 10**9 + 1

def main():
    N,M,K = [int(i) for i in input().strip().split()]
    A_l = deque([int(i) for i in input().strip().split()])
    B_l = deque([int(i) for i in input().strip().split()])

    top_a = A_l.popleft()
    top_b = B_l.popleft()

    ans = 0

    while top_a <= K or top_b <= K:
        if top_a < top_b:
            K -= top_a
            ans += 1
            if len(A_l) > 0:
                top_a = A_l.popleft()
            else:
                top_a = INF
        else:
            K -= top_b
            ans += 1
            if len(B_l) > 0:
                top_b = B_l.popleft()
            else:
                top_b = INF

    return ans

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

A.append(-1)
B.append(-1)

ans = 0
ai = 0
bi = 0
time = k
while True:
  if A[ai] != -1 and B[bi] != -1:
    if A[ai] < B[bi] and time >= A[ai]:
      time -= A[ai]
      ans += 1
      ai += 1
    elif A[ai] > B[bi] and time >= B[bi]:
      time -= B[bi]
      ans += 1
      bi += 1
    else:
      break
  elif A[ai] != -1:
    if time >= A[ai]:
      time -= A[ai]
      ans += 1
      ai += 1
    else:
      break
  elif B[bi] != -1:
    if time >= B[bi]:
      time -= B[bi]
      ans += 1
      bi += 1
    else:
      break
  else:
    break

print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    def input():
        return sys.stdin.readline()[:-1]
    S=list(map(int,input().split()))
    A=list(map(int,input().split()))
    B=list(map(int,input().split()))
    N=S[0]
    M=S[1]
    K=S[2]
    nokori=K
    Ahon=A[0]
    Bhon=B[0]
    kazu=0
    i=0
    j=0
    k=2
    while nokori>0 and k>0:
        if Ahon > Bhon and nokori>=Bhon:
            kazu+=1
            i+=1
            nokori -= Bhon
            if i>=M:
                Bhon=max(A)+1
                k -= 1
            else:
                Bhon=B[i]
            

        elif Ahon <= Bhon and nokori>=Ahon:
            kazu+=1
            j+=1
            nokori -= Ahon
            if j>=N:
                Ahon=max(B)+1
                k -= 1
            else:
                Ahon=A[j]
        else:
            break
    print(kazu)



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_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 >= total_time + a[a_counter]:
            total_time += a[a_counter]
            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 >= total_time + b[b_counter]:
            total_time += b[b_counter]
            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 >= total_time + a[a_counter]:
            total_time += a[a_counter]
            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 >= total_time + b[b_counter]:
            total_time += b[b_counter]
            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:
def main():
    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    A = A + [10**10]
    B = B + [10**10]

    answer = 0
    reqTime = 0

    Ai = 0
    Bi = 0

    while True:
        if(K < (reqTime + min(A[Ai], B[Bi]))):
            print(answer)
            return

        if(A[Ai] < B[Bi]):
            reqTime = reqTime + A[Ai]
            Ai = Ai + 1
        else:
            reqTime = reqTime + B[Bi]
            Bi = Bi + 1

        answer = answer + 1
        

if __name__ == "__main__":
    main()

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]

#print(a)
#print(b)
ans = 0
while 1:
    #print(k, a,b)
    if b == [] and a == []:
        break
    elif b == [] and a != []:
        if a[-1] <= k:
            k -= a.pop()
            ans += 1
            continue
        else:
            break
    elif a == [] and b != []:
        if b[-1] <= k:
            k -= b.pop()
            ans += 1
            continue
        else:
            break
    if a[-1] > b[-1]:
        if b[-1] <= k:
            k -= b.pop()
            ans += 1
        else:
            break
    else:
        if a[-1] <= k:
            k -= a.pop()
            ans += 1
        else:
            break



print(ans)

Submission status: Wrong Answer

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

for i in range(M+N):
  if A[0] <= B[0]:
    K = K - A[0]
    if K < 0:
      break
    count += 1
    A.pop(0)
    if not A:
      A.append(10**9)
  elif A[0] >= B[0]:
    K = K - B[0]
    if K < 0:
      break
    count += 1
    B.pop(0)
    if not B:
      B.append(10**9)

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()))
t=0
#aaは目印（本の数−１）
aa=n-1
for i in range(n):
    t+=a[i]
    if t>k:
        aa=i-1
        t-=a[i]
        break
ans=[aa+1]
f=aa+1
s=0
for i in range(m):
    t+=b[i]
    f+=1
    while t>k:
        if aa<0:
            s=1
            break
        else:
            t-=a[aa]
            aa-=1
            f-=1
    ans.append(f)
    if s==1:
        break

print(max(ans))

Submission status: Wrong Answer

Solution code:
try:
    n,p,t=map(int,input().split(" "))
    lia=list(map(int,input().split(" ")))
    lib=list(map(int,input().split(" ")))
    sum=0
    i=0
    j=0
    count=0
    while sum<=t:
            if sum+lia[i]>t :
                if sum+lib[i]>t:
                    break
            if lia[i]<=lib[j] and i<n :
                sum+=lia[i]
                i+=1
                count+=1
            elif lia[i]>=lib[j] and j<p :
                sum+=lib[j]
                j=j+1
                count+=1
            else:
                break
            print(sum)

    print(count)
except:
    pass

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = []
ans = 0
m = 0
C.extend(A)
C.extend(B)
C = sorted(C)
for i in range(len(C)):
    m += C[i]
    if m > K:
        print(ans)
        exit()
    else:
        ans += 1
print(ans)

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

i = 0
j = 0
T = 0
cnt = 0

while T <= K:
  if i == N and j == M:
    break
  elif i == N:
    T += Bs[j]
    j += 1
  elif j == M:
    T += As[i]
    i += 1
  else:
    if As[i] > Bs[j]:
      T += Bs[j]
      j += 1
    elif As[i] < Bs[j]:
      T += As[i]
      i += 1
    else:
      if i+1 == N:
        T += Bs[j]
        j += 1
      elif j+1 == M:
        T += As[i]
        i += 1
      elif As[i+1] >= Bs[j+1]:
        T += Bs[j]
        j += 1
      else:
        T += As[i]
        i += 1
  cnt += 1
  
if T > K:
  print(cnt-1)
else:
  print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import deque

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


time = 0
ans = 0

while time < k:
    if not (a and b):
        remain = a + b

        while remain:
            time += remain.popleft()

            if time > k:
                break

            ans += 1

        break

    if a[0] < b[0]:
        time += a.popleft()
    else:
        time += b.popleft()

    if time > k:
        break

    ans += 1


print(ans)

Submission status: Wrong Answer

Solution code:
input_list = input().split(" ")
n = int(input_list[0])
m = int(input_list[1])
k = int(input_list[2])
con1 = n >= 1 and n <= 200000
con2 = m >= 1 and m <= 200000
con3 = k >= 1 and k <= 1000000000
lista = list()
listb = list()
result = 0
if con1 == True and con2 == True and con3 == True:
    lista = input().split(" ")
    listb = input().split(" ")
    for i in lista:
        if int(i) <= k and k > 0:
            k = k - int(i)
            result = result + 1
        else:
            continue
    for i in listb:
        if int(i) <= k and k > 0:
            k = k - int(i)
            result = result + 1
        else:
            continue
    print(result)
else:
    print()

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

count = 0
spend = 0
ia = 0
ib = 0
tmpa = A[0]
tmpb = B[0]
while spend < k:
  if ia < n and tmpa < tmpb:
    spend += tmpa
    ia += 1
    if ia == n:
      tmpa = 10**9
    else:
      tmpa = A[ia]
  elif ib < m and tmpa >= tmpb:
    spend += tmpb
    ib += 1
    if ib == m:
      tmpb = 10**9
    else:
      tmpb = B[ib]
  elif ia == n:
    spend += tmpb
    ib += 1
    if ib == m:
      tmpb = 10**9
    else:
      tmpb = B[ib]
  elif ib == m:
    spend += tmpa
    ia += 1
    if ia == n:
      tmpa = 10**9
    else:
      tmpa = A[ia]
    
  count += 1
print(count-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()))

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