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 bisect
N,M,K=map(int,input().split())
A=[int(x) for x in input().split()]
B=[int(y) for y in input().split()]
ans=0
a_nowtime=0
B_time=[0]*M
kari=0#time
for j in range(M):
    kari+=B[j]
    B_time[j]=kari
kari=0#numofbookofa+b

for i in range(N):
    a_nowtime+=A[i]
    if a_nowtime>K:
        break
    time=K-a_nowtime
    num=bisect.bisect_right(B_time,time)
    kari=i+1+num
    ans=max(ans,kari)

print(ans)

Submission status: Wrong Answer

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

a = a[::-1]
b = b[::-1]

s = 0
swi = 0
ans = 0
while k>0:
	if len(a)>0 and len(b)>0:
		if a[-1]==b[-1]:
			if swi==0:
				for i in range(2, min(len(a), len(b))+1):
					if a[-i]!=b[-i]:
						if a[-i]>b[-i]:
							swi = 1				
						else:
							swi = -1
						break
				else:
					if len(a)>=len(b):
						swi = 1
					else:
						swi = -1
			if swi==1:
				k-=a.pop()
				if k>=0:ans+=1
			if swi==-1:
				k-=b.pop()
				if k>=0:ans+=1
		elif a[-1]>b[-1]:
			swi = 0
			k-=b.pop()
			if k>=0:ans+=1
		elif a[-1]<b[-1]:
			swi = 0
			k-=a.pop()
			if k>=0:ans+=1
	elif len(a)==0:
		while k>0 and len(b)>0:
			k-=b.pop()
			if k>=0:ans+=1
		break
	elif len(b)==0:
		while k>0 and len(a)>0:
			k-=a.pop()
			if k>=0:ans+=1
		break


print(ans)

Submission status: Wrong Answer

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

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

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

print(book)

Submission status: Wrong Answer

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

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

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

        if a_v < b_v:
            k -= a_v
            a += 1
        else:
            k -= b_v
            b += 1

        if k >= 0:
            r += 1

        if k <= 0:
            return r
    return r

if __name__ == "__main__":
    n, m, k = map(int, input().split())
    a_n = [int(x) for x in input().split()]
    b_n = [int(x) for x in input().split()]
    print(int(main(n, m, k, a_n, b_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()))

cnt = 0

a_cnt = 0

b_cnt = 0

num = 0
while num < K:
    if N == a_cnt:
        if M == b_cnt:
            break
        else:
            num += b[b_cnt]
            b_cnt += 1
    elif M == b_cnt:
        if N == a_cnt:
            break
        else:
            num += a[a_cnt]    
            a_cnt += 1
    elif a[a_cnt] < b[b_cnt]:
        num += a[a_cnt]
        a_cnt += 1
    else:
        num += b[b_cnt]
        b_cnt += 1
    cnt += 1
print(cnt)

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

        sum_A = []
        sum_A.append(A[0])
        sum_B = []
        sum_B.append(B[0])

        for i in range(N-1):
                A[i+1] += A[i]
                if A[i+1]<=K:
                        sum_A.append(A[i+1])
                else:
                        break

        for i in range(M-1):
                B[i+1] += B[i]
                if B[i+1]<=K:
                        sum_B.append(B[i+1])
                else:
                        break

        max_ij = 0
        for i in range(len(sum_A)):
                if sum_A[i]<=K:
                        for j in range(len(sum_B)):
                                if sum_B[j]<=K:
                                        temp = sum_A[i]+sum_B[j]
                                        if temp<=K:
                                                max_ij = max(max_ij,i+j+2)
        ans = max_ij

        return int(ans)

if __name__=="__main__":
        ans = main()
        print(ans)

Submission status: Wrong Answer

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

maxrecord = 0

for i in range(1, n + 1):
    left = k - sum(a[:i])
    if left < 0:
        counter = i - 1
        if maxrecord < counter:
            maxrecord = counter
        break
    counter = i

    for j in range(1, m + 1):
        if left - sum(b[:j]) < 0:
            if maxrecord < counter:
                maxrecord = counter
            break
        counter += 1

print(counter)

Submission status: Wrong Answer

Solution code:
from collections import deque
n,m,k=[int(_) for _ in input().split()]
A=deque([int(_) for _ in input().split()])
B=deque([int(_) for _ in input().split()])
jikan=0
yomi=0
while (A or B):
    if A and B:
        if A[0]<=B[0]:
            jikan+=A.popleft()
        else:
            jikan+=B.popleft()
    elif A:
        jikan+=A.popleft()
    else:
        jikan+=B.popleft()
    
    if jikan<=k:
        yomi+=1
    else:
        break
print(yomi)

Submission status: Wrong Answer

Solution code:
import sys
#机Aの本の数N, 机Bの本の数M, 限界合計所要時間K
N, M, K = map(int, input().split())

#机Aの本を読むのにかかる時間A
A = list(map(int, input().split()))

#机Bの本を読むのにかかる時間B
B = list(map(int, input().split()))
A.append(200001)
B.append(200001)

ans = K
cou = 0
while A[0] <= ans or B[0] <= ans:
    if A[0] >= B[0]:
        ans = ans - B.pop(0)
        cou += 1
        #print(ans)
        #print("B")
        #sys.exit()
    else:
        ans = ans - A.pop(0)
        cou += 1
        #print(ans)
        #print("A")
        #sys.exit()

print(cou)

Submission status: Wrong Answer

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

a = 0
b = 0
time = 0

for n in range(200000 + 200000):
    if a < len(A):
        if b < len(B):
            if A[a] > B[b]:
                time += B[b]
                b += 1

                if time > K:
                    b -= 1
            else:
                time += A[a]
                a += 1

                if time > K:
                    a -= 1
        else:
            time += A[a]
            a += 1

            if time > K:
                a -= 1
    else:
        if b < len(B):
            time += B[b]
            b += 1

            if time > K:
                b -= 1
        else:
            break
    
    if time > K:
        break

print(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()))
ans = 0
rest = k
sm = 0
end = -1
for j, b in enumerate(B):
    sm += b
    if sm < k:
        end = j
    else:
        sm -= b
        break
ans = end+1
for i, a in enumerate(A):
    sm += a
    if sm <= k:
        ans = max(end+1+i+1, ans)
        break
    else:
        for j, b in enumerate(B[:end+1][::-1]):
            sm -= b
            if sm <= k:
                end -= j+1
                ans = max(end+1+i+1, ans)
                break
print(ans)

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

cA = list(itertools.accumulate(A))
cB = list(itertools.accumulate(B))

#print(cA)
#print(cB)

ans = 0
for i in range(n):
    tmp = cA[-(i+1)]
    if tmp < k:
        indb = bisect.bisect_right(cB, k - tmp)
        #print(indb)
        ans = max(ans, (n-i)+indb)
    elif tmp == k:
        ans = n - i
    
print(ans)

Submission status: Wrong Answer

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

ans=0
total=0
flag=True
while flag==True:
    if len(A)==0:
        A.append(10**9+1)
        #10**10でオーバーフローするらしい
    elif len(B)==0:
        B.append(10**9+1)
    elif A[0]<=B[0]:
        a=A.pop(0)
        if total+a<=K:
            ans+=1
            total+=a
        else:
            flag=False
    else:
        b=B.pop(0)
        if total+b<=K:
            ans+=1
            total+=b
        else:
            flag=False

print(ans)

Submission status: Wrong Answer

Solution code:
a=[]
b=[]
lst=[]
str = input()
str1 = input()
str2 = input()
lst = str.split(' ')
n,m,k = lst
n = int(n)
m = int(m)
k = int(k)

a = str1.split(' ')
b = str2.split(' ')
i=0
j=0
count = 0
c=0
flaga=0
flagb = 0
#print(a)
#print(k)
while c<=k and flaga==0 and flagb==0 and count<len(a)+len(b):
  
  
  if i<len(a):
    
    c = c+int(a[i])
    if c<=k:
      #a.pop(i)
      i = i+1
      count = count+1
    else:
      c = c-int(a[i])
      flaga=1
  #print("c:",c)
  if j<len(b):
    c = c+int(b[j])
    if c<=k:
      #b.pop(j)
      j = j+1
      count = count+1
    else:
      c = c-int(b[j])
      flagb=1
    #print("c:",c)
print(count)

Submission status: Wrong Answer

Solution code:
def count_books(books, limit):
    num_books = len(books)
    total_time = 0
    for i, time in enumerate(books):
        if total_time + time > limit:
            num_books = i
            break
        total_time += time
    return [num_books, total_time]

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

    max_num_A, total_time_A = count_books(A, K)

    read_book_nums = [0] * (max_num_A + 1)

    remain = K - total_time_A
    num_B, total_time_B = count_books(B, remain)
    read_book_nums[-1] = max_num_A + num_B

    num_A = max_num_A
    m = 0
    total_time_B = 0
    for n in range(max_num_A-1, -1, -1):
        num_A -= 1
        remain += A[n-1]

        while m < M and total_time_B + B[m] < remain:
            total_time_B += B[m]
            m += 1
        num_B = m

        read_book_nums[n] = num_A + num_B

    print(max(read_book_nums))
    
main()

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 (ans<n+m)&(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()))

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:
N,M,K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ABuckup = A
BBuckup = B
countNum = 0
countNumTemp = countNum
countTime = 0
countTimeTemp = countTime
loopNum = max(N,M)
while countTimeTemp <= K:
    countTime = countTimeTemp
    countNum = countNumTemp
    try:
        if A[0] <= B[0]:
            countTimeTemp += A.pop(0)
            countNumTemp += 1
        else:
            countTimeTemp += B.pop(0)
            countNumTemp += 1
    except:
        if len(A) != 0:
            countTimeTemp += A.pop(0)
            countNumTemp += 1
        elif len(B) != 0:
            countTimeTemp += B.pop(0)
            countNumTemp += 1
        else:
            break
A = ABuckup
B = BBuckup
countNumA = 0
countTimeA = 0
for i,v in enumerate(A):
    countTimeA += v
    if countTimeA <= K:
        countNumA += 1
countNumB = 0
countTimeB = 0
for i,v in enumerate(B):
    countTimeB += v
    if countTimeB <= K:
        countNumB += 1
print(max(countNum,countNumA,countNumB))

Submission status: Wrong Answer

Solution code:
import random
n, m, k = map(int, input().split())
# n, m, k = random.randint(1, 10**5), random.randint(1, 10**5), random.randint(10**8, 10**9)
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
# a_list = [random.randint(1, 10**7) for i in range(n)]
# b_list = [random.randint(1, 10**7) for i in range(m)]
# print(n,m,k)
# print(a_list[0], b_list[0])
a_sum = [0]
b_sum = [0]
max_a = 0
max_b = 0
for i in range(1, max(n+1, m+1)):
    if i < n+1:
        a_sum.append(a_sum[i-1] + a_list[i-1])
        if a_sum[i] < k:
            max_a = i
    if i < m+1:
        b_sum.append(b_sum[i-1] + b_list[i-1])

max_num = max_a
# print(max_a)
while max_a > -1:
    while max_b < m and b_sum[max_b] <= k-a_sum[max_a]:
        max_b += 1
    if max_num < max_a + max_b:
        max_num = max_a + max_b
        # print(max_a, max_b)
    max_a -= 1

print(max_num)

Submission status: Wrong Answer

Solution code:
import math

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

time = 0
a_i = 0
b_i = 0
while time <= k:
    if a_i >= n:
        cur_a = math.inf
    else:
        cur_a = alist[a_i]

    if b_i >= m:
        cur_b = math.inf
    else: 
        cur_b = blist[b_i]

    if cur_a == math.inf and cur_b == math.inf:
        break

    if cur_a < cur_b:
        time += alist[a_i]
        a_i += 1
    else:
        time += blist[b_i]
        b_i += 1

if time <= k:
    print(a_i+b_i)
else:
    print(a_i+b_i)

Submission status: Wrong Answer

Solution code:
n,m,k = map(int,input().split())
ali = list(map(int,input().split()))
bli = list(map(int,input().split()))
lia,lib = [ali[0]],[bli[0]]
for i in range(1,n):
    lia.append(lia[i-1]+ali[i])
for i in range(1,m):
    lib.append(lib[i-1]+bli[i])
a = [0]
for i in range(n):
    for j in range(m):
        if lia[i] + lib[j] <= k:
            a.append(i+j+2)
print(max(a))

Submission status: Wrong Answer

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



def solve(N: int, M: int, K: int, A: "List[int]", B: "List[int]"):
    acount=0
    bcount=0
    nowtime=0
    while True:
        if acount==N and bcount==M:break
        if acount==N:
            if B[bcount]+nowtime>K:break
        elif bcount==M:
            if A[acount]+nowtime>K:break
        else:
            if A[acount]+nowtime>K and B[bcount]+nowtime>K:break
        if acount==N:
            #print("Bfuck")
            nowtime+=B[bcount]
            bcount+=1
            continue
        if bcount==M:
            #print("Afuck")
            nowtime+=A[acount]
            acount+=1
            continue
        
        if A[acount]<=B[bcount]:
            #print("A")
            nowtime+=A[acount]
            acount+=1
        else:
            #print("B")
            nowtime+=B[bcount]
            bcount+=1
    print(acount+bcount)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    B = [int(next(tokens)) for _ in range(M)]  # type: "List[int]"
    solve(N, M, K, A, B)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# c
 
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
sum = 0
num = 0
lim = max(n, m)
m = min(n-1, m-1)
if m == n-1:
    y = b
else:
    y = a
for i in range(lim):
    if i <= m:
        if a[i] <= b[i]:
            if (sum + a[i]) <= k:
                sum += a[i]
                num += 1
            else:
                break
            if sum + b[i] <= k:
                sum += b[i]
                num += 1
            else:
                break
        else:
            if sum + b[i] <= k:
                sum += b[i]
                num += 1
            else:
                break
            if sum + a[i] <= k:
                sum += a[i]
                num += 1
            else:
                break
    else:
        if sum + y[i] <= k:
            sum += y[i]
            num += 1
        else:
            break
 
print(num)

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
if sum(AB) <= K:
  print(leng)
  sys.exit()
for i in range(leng):
  time += AB[i]
  if time <= K:
    num += 1
  else:
    break
print(num)

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

sumAlist = []
sumBlist = []
for i in range(len(A)):
  if(i==0):
    if(A[i] <= K):
      sumAlist.append(A[i])
    else:
      break
  else:
    if(sumAlist[i-1]+A[i] <= K):
      sumAlist.append(sumAlist[i-1]+A[i])
    else:
      break
for i in range(len(B)):
  if(i==0):
    if(B[i] <= K):
      sumBlist.append(B[i])
    else:
      break
  else:
    if(sumBlist[i-1]+B[i] <= K):
      sumBlist.append(sumBlist[i-1]+B[i])
    else:
      break
lenA = len(sumAlist)
lenB = len(sumBlist)
ans = max(lenA,lenB)
preans = ans
if(lenA==0):
  print(lenB)
elif(lenB==0):
  print(lenA)
elif(sumAlist[-1]+sumBlist[-1] <= K):
    print(lenA + lenB)
else:
  for i in range(lenA):
    tempsum = sumAlist[i]
    j = preans - (i+1)
    while(1):
      if(tempsum <= K and j<lenB):
        if(tempsum + sumBlist[j] <= K):
          #print("ij =",i,j)
          tempsum += sumBlist[j]
          j += 1
        else:
          break
      else:
        break
    ans = max(ans,i+j+1)
    #print(ans)
  #print("ans =",ans)
  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()))

max_k = 10**9

sum_A = []
tmp = 0
rest_a = k
for i, a in enumerate(A):
    sum_A.append(a + tmp)
    tmp += a
    rest_a -= a
    if tmp >= k or i+1 == len(A):
        threthold_a = i+1
        break

sum_B = []
tmp = 0
rest_b = k
for i, b in enumerate(B):
    sum_B.append(b + tmp)
    tmp += b
    rest_b -= b
    if tmp >= k or i+1 == len(B):
        threthold_b = i+1
        break
    
if threthold_a > threthold_b:
    sum_C = sum_B
    rest = rest_a
    count = threthold_a
elif threthold_a < threthold_b:
    sum_C = sum_A
    rest =rest_b
    count = threthold_b
elif sum_A[threthold_a-1] > sum_B[threthold_b-1]:
    sum_C = sum_A
    rest = rest_b
    count = threthold_b
else:
    sum_C = sum_B
    rest =rest_a
    count = threthold_a

if rest < 0:
    print(0)
    exit()

for c in sum_C:
    if c <= rest:
        count += 1
    else:
        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()))
cnt=0
temp=0
Ai=0
Bi=0
for i in range(n+m):
  if Ai==n and Bi==m:
    exit()
  elif Ai==n and Bi<=m-1:
    if temp+B[Bi]<=k:
      temp+=B[Bi]
      cnt+=1
      Bi+=1
    else:
      exit()
  elif Bi==m and Ai<=n-1:
    if temp+A[Ai]<=k:
      temp+=A[Ai]
      cnt+=1
      Ai+=1
    else:
      exit()
  elif Ai<=n-1 and Bi<=m-1:
    if A[Ai]<=B[Bi]:
      if temp+A[Ai]<=k:
        temp+=A[Ai]
        cnt+=1
        Ai+=1
      else:
        exit()
    elif A[Ai]>B[Bi]:
      if temp+B[Bi]<=k:
        temp+=B[Bi]
        cnt+=1
        Bi+=1
      else:
        exit()
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.sort()
b.sort()
ans=0
i=0
j=0
while (k>=0 and i <n and j<m):
    if a[i]<b[j]:
        k-=a[i]
        i+=1
    else:
        k-=b[j]
        j+=1
    if k>=0:
        ans+=1
while(k>=0 and i<n):
    k-=a[i]
    i+=1
    if k>=0:
        ans+=1
while(k>=0 and j<m):
    k-=b[j]
    j+=1
    if k>=0:
        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())) 

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

i, j = 0, 0
ans = 0
time = 0

for _ in range(m+n):
    s, t = a[i], b[j]

    # print(f'{s} {t}')
    # print(f'{i} {j}')

    # if s <= t and i < n:
    if s <= t:
        if i >= n-1:
            s = 10**18
        else:
            i += 1
            time += s
        # ans += 1

    if s > t:
        if j >= m-1:
            t = 10**18
        else:
            j += 1
            time += t
    

    if time > k:
        break

    ans += 1


# mn = min(a[0], b[0])
# k -= mn

# while time <= k:
#     # print(f'{i} {j}')
#     s, t = a[i], b[j]
    
#     mn = min(s, t)

#     if s <= t and i < n-1:
#         i += 1
#     if s > t and j < m-1:
#     # else:
#         j += 1

#     time += mn

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

result=[]
while True:
    if len(A)>0 and len(B)>0:
        if A[0] < B[0]:
            result.append(A[0])
            A.pop(0)
            if sum(result) > K:
                break
        else:
            result.append(B[0])
            B.pop(0)
            if sum(result) > K:
                break
    elif len(A)==0 and len(B)>0:
        result.append(B[0])
        B.pop(0)
        if sum(result) > K:
            break
    elif len(A)>0 and len(B)==0:
        result.append(A[0])
        A.pop(0)
        if sum(result) > K:
            break
    else:
        result.append("END")
        break
print(len(result)-1)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))+[pow(10,9)]*3
b=list(map(int,input().split()))+[pow(10,9)]*3
if n>m:
  b=b+[pow(10,9)]*(n-m)
elif n<m:
  a=a+[pow(10,9)]*(m-n)
i,j=0,0
for l in range(n+m):
    x=min(a[i],b[j])
    k-=x
    if k<0:
        print(l)
        exit()
    if k==0:
        print(l+1)
        exit()
    if a[i]==b[j]:
        if a[i+1]<b[j+1]:
            i+=1
        elif a[i+1]>b[j+1]:
            j+=1
        else:
          if a[i+2]<=b[j+2]:
            i+=1
          elif a[i+2]>b[j+2]:
            j+=1
    if i<n and x==a[i]:
        i+=1
    elif j<m and x==b[j]:
        j+=1
print(n+m)

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+1)
B.append(10**10+1)
ans=0
time=0
a=0
b=0
while K>time:
    if time+min(A[a],B[b])>K:
        break
    ans+=1
    time+=min(A[a],B[b])
    if A[a]>B[b]:
        b+=1
    else:
        a+=1
    if ans==N+M:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
a=[]
b=[]
lst=[]
str = input()
str1 = input()
str2 = input()
lst = str.split(' ')
n,m,k = lst
n = int(n)
m = int(m)
k = int(k)

a = str1.split(' ')
b = str2.split(' ')
i=0
j=0
count = 0
c=0
flaga=0
flagb = 0
print(a)
print(k)
while c<=k and flaga==0 and flagb==0 and count<len(a)+len(b):
  
  
  if i<len(a):
    
    c = c+int(a[i])
    if c<=k:
      #a.pop(i)
      i = i+1
      count = count+1
    else:
      c = c-int(a[i])
      flaga=1
  print("c:",c)
  if j<len(b):
    c = c+int(b[j])
    if c<=k:
      #b.pop(j)
      j = j+1
      count = count+1
    else:
      c = c-int(b[j])
      flagb=1
    print("c:",c)
print(count)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
a = []
b= []
a= list(map(int, input().split()))
b= list(map(int, input().split()))
a.append(10**10)
b.append(10**10)
t = 0
i = 0
while t<=k:
    t = t + min(a[0],b[0])
    if t >k:
        break
    i = i +1
    if a[0]==min(a[0], b[0]):
        a.remove(min(a[0], b[0]))
    else:
        b.remove(min(a[0],b[0]))
print(i)

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
for i in range(N+M):
    if time_count >= K:
        break
    if len(A) > 0 and len(B) > 0:
        if A[0] > B[0]:
            time_count += B[0]
            B.pop(0)
            book_count += 1
        else:
            time_count += A[0]
            A.pop(0)
            book_count += 1
    elif len(A) == 0 and len(B) > 0:
        time_count += B[0]
        book_count += 1
    elif len(A) > 0 and len(B) == 0:
        time_count += A[0]
        book_count += 1

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

Submission status: Wrong Answer

Solution code:

N, M, K = map(int, input().split())
A = [i for i in map(int, input().split())]
B = [i for i in map(int, input().split())]

time = 0
books = 0
for i in range(N+M):
    if not A:
        A = [float('inf'), 1]
    if not B:
        B = [float('inf'), 1]
    if (time + min(A[0], B[0]))> K:
        break
    else:
        if A[0] < B[0]:
            Time = A.pop(0)
            time += Time
            books += 1
        else:
            Time = B.pop(0)
            time += Time
            books += 1

print(books)

Submission status: Wrong Answer

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

inf = 10**9+1
X = [inf]*200010
Y = [inf]*200010

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

for a in range(N):
    X[a] = A[a]
for b in range(M):
    Y[b] = B[b]

ans = 0
T = 0
while K - T >= 0:
    tmp = min(X[0],Y[0])
    T += tmp
    if tmp == X[0]:
        X.pop(0)
    elif tmp == Y[0]:
        Y.pop(0)
    ans += 1

print(ans - 1)

Submission status: Wrong Answer

Solution code:
N, M, K=[int(i) for i in input().split(" ")]
a=[int(i) for i in input().split(" ")]
b=[int(i) for i in input().split(" ")]

time=0
a_idx=0
b_idx=0
count=0
while time<K:
    count+=1
    try:
        if a_idx+1==N:
            time+=b[b_idx]
            b_idx+=1
            if time>K:
                count-=1
            continue
        elif b_idx+1==M:
            time+=a[b_idx]
            a_idx+=1
            if time>K:
                count-=1
            continue    
        
        if a[a_idx]<b[b_idx]:
            time+=a[a_idx]
            a_idx+=1
            
        elif a[a_idx]>b[b_idx]:
            time+=b[b_idx]
            b_idx+=1
        else:
            a_com=a_idx
            b_com=b_idx

            if a[a_com]>b[b_com]:
                time+=a[a_idx]
                a_idx+=1

            elif a[a_com]<b[b_com]:
                time+=b[b_idx]
                b_idx+=1

        if time>K:
            count-=1            
    except:
        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_sum = 0
A_max = 0
B_sum = 0
B_max = 0
best_num = 0
A_max = N
for i in range(N):
    A_sum += A[i]
    if A_sum > K:
        A_sum -= A[i]
        A_max = i
        break
A = A[0:A_max]
best_num = 0
now_num = A_max
mixsum = A_sum
A.reverse()
for i in range(A_max):
    A_sum -= A[i]
    mixsum = A_sum
    now_num = A_max - i
    for j in range(M):
        mixsum += B[j]
        now_num += 1
        if mixsum > K:
            now_num -= 1
            break
    if now_num > best_num:
        best_num = now_num
print(best_num)