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 sys

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

    yomuA = a[0]
    yomuB = b[0]
    ans = []
    
    countA = 0
    countB = 0

    for i in range(n+m):
        if (yomuA < yomuB):
            if (countA < n-1):
                ans.append(yomuA)
                countA += 1
                yomuA = a[countA]
            elif (countA == n-1):
                ans.append(yomuA)
                for j in range(countB, m):
                    ans.append(b[j])
                break
        else:
            if (countB < m-1):
                ans.append(yomuB)
                countB += 1
                yomuB = b[countB]
            elif(countB == m-1):
                ans.append(yomuB)
                for k in range(countA, n):
                    ans.append(a[k])
                break


    sum_ = 0
    for i in range(len(ans)):
        sum_ += ans[i]
        if (sum_ > k):
            print(i)
            break
        elif(i == len(ans)-1):
            print(i+1)

main()

Submission status: Wrong Answer

Solution code:
# 初期入力
from collections import deque
import sys
input = sys.stdin.readline
N,M,K = (int(i) for i in input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
dq_a =deque(A)
dq_b =deque(B)

#上から読む＝配列の前から読む
read_time =0
ans =0
a=dq_a.popleft()
b=dq_b.popleft()
for i in range(N+M):
    if a <=b and read_time +a <=K:
        read_time +=a
        ans +=1
        if len(dq_a) >0:
            a =dq_a.popleft()
        else:
            a=10**9 +1
    if a >=b and read_time +b <=K:
        read_time +=b
        ans +=1
        if len(dq_b) >0:
            b =dq_b.popleft()
        else:
            b=10**9 +1
    if read_time >K:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int,input().split())
AL = list(map(int, input().split()))
BL = list(map(int, input().split()))
AL.extend(BL)
AAL = sorted(AL)

if sum(AAL) == K:
    print(len(AAL))
    exit()

cnt = 0
ans = 0
for i in range(N+M):
    cnt += AAL[i]
    ans += 1
    if cnt >= K:
        print(ans-1)
        exit()

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

while (a != []) or (b != []):
    if not a:
        k -= b[0]
        if k < 0: break
        del b[0]
    elif not b:
        k -= a[0]
        if k < 0: break
        del a[0]
    elif a[0] <= b[0]:
        k -= a[0]
        if k < 0: break
        del a[0]
    else:
        k -= b[0]
        if k < 0: break
        del b[0]
    count += 1

print(count)

Submission status: Wrong Answer

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

i,j=0,0
lA,lB=len(A),len(B)

while True:
  if K<=0:
    break
  if A[i]<=B[j] and i<lA:
    K-=A[i]  
    i+=1  
  elif B[j]<=A[i] and j<lB:
    K-=B[j]     
    j+=1
  if i>=lA and K>0:
    while j<lB and K>=0:
      K-=B[j]
      j+=1
  elif j>=lB and K>0:
    while i<lA and K>=0:
      K-=A[i]
      i+=1

count=i+j-1 if K<0 else i+j
print(count)

Submission status: Wrong Answer

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

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

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

re = i = 0

A.extend(B)
A.sort()

while(m > 0 and i < a+b):
    m -= A[i]
    if(m >= 0):
        re += 1
        i+=1
print(re)

Submission status: Wrong Answer

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

ABlist = []
book = 0
nm = n+m
while (len(ABlist) < nm):
    if (len(Alist) == 0):
        ABlist += Blist
        break
    elif (len(Blist) == 0):
        ABlist += Alist
        break

    if (Alist[0] < Blist[0]):
        ABlist.append(Alist[0])
        Alist.pop(0)
    else:
        ABlist.append(Blist[0])
        Blist.pop(0)

while (True):
    if (len(ABlist) == 0):
        break
    if (k - ABlist[0] >= 0):
        k -= ABlist[0]
        ABlist.pop(0)
        book += 1
    else:
        break
print(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()))
tt = 0
a = 0
b = 0
if (K >= (sum(A)+sum(B))):
    print(N+M)
elif (A[a]>K)and(B[b]>K):

    print(0)
else:
    while (tt <= K ):
        print(tt)

        if (a < N)and (b < M):
            if A[a]>B[b]:
                tt += B[b]
                b += 1
                if tt > K:
                    b -= 1
                    break

                elif tt == K:
                    break
            elif A[a]<B[b]:
                tt += A[a]
                a += 1
                if tt > K:
                    a -= 1
                    break

                elif tt == K:
                    break
            elif (A[a]==B[b])and(a < N-1)and (b < M-1):
                if A[a+1]>B[b+1]:
                    tt += B[b]
                    b += 1
                    if tt > K:

                        b -= 1
                        break
                    elif tt == K:
                        break
            elif (A[a]==B[b]):
                tt += B[b]
                b += 1
                if tt > K:

                    b -= 1
                    break
                elif tt == K:
                    break

                
            
        elif (a == N)and (b < M):
            tt += B[b]
            b += 1
            if tt > K:
                b -= 1
                break

            elif tt == K:
                break
        elif (a < N)and (b == M):
            tt += A[a]
            a += 1
            if tt > K:
                a -= 1
                break

            elif tt == K:
                break
        else:
            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()))

time = 0
a = 0
b = 0
while True:
    if time > K:
        break
    if time == K:
        break
    if a == N and B == M:
        break
    if a == N:
        time += B[b]
        b += 1
    elif b == M:
        time += A[a]
        a += 1
    elif A[a] <= B[b]:
        time += A[a]
        a += 1
    elif B[b] < A[a]:
        time += B[b]
        b += 1
    
print(a+b if time <= K else a+b-1)

Submission status: Wrong Answer

Solution code:
acount = 0
bcount = 0

a,b, limit = map(int, input().split())

curr_time = 0
books = 0
a_books = list(map(int, input().split()))
b_books = list(map(int, input().split()))

while curr_time < limit:
  time = 0
  if acount < a:
    if bcount < b:
      if a_books[acount] < b_books[bcount]:
        time= a_books[acount]
        acount += 1
      else:
        time = b_books[bcount]
        bcount += 1
    else: 
      time = a_books[acount]
      acount += 1
  else:
    time = b_books[bcount]
    bcount += 1
  if curr_time + time <= limit: books += 1
  curr_time += time
    
    
print(books)

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
flag = True
while True:
  tar = min(a[0], b[0])
  if (tar == a[0]):
    del a[0]
  else:
    del b[0]

  time += tar
  ans += 1
  if (time > k):
    ans -= 1
    break

  if (len(a) == 0):
    flag = False
    lis = b
    break
  if (len(b) == 0):
    flag = False
    lis = a
    break

if (flag is False):
  while True:
    time += lis[0]
    ans += 1
    if (time > k):
      time -= lis[0]
      ans -= 1
      break
    
    del lis[0]
    if (len(lis) == 0):
      break

print(ans)

Submission status: Wrong Answer

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

time = 0
cnt = 0
for i in range(N*K):
    if len(al) >= 1 and len(bl) >= 1:
        if al[0] >= bl[0]:
            time += bl.popleft()
            if time > K:
                print(cnt)
                exit()
            else:
                cnt += 1
        else:
            time += al.popleft()
            if time > K:
                print(cnt)
                exit()
            else:
                cnt += 1
    elif len(al) >= 1:
        time += al.popleft()
        if time > K:
            print(cnt)
            exit()
        else:
            cnt += 1
    elif len(bl) >= 1:
        time += bl.popleft()
        if time > K:
            print(cnt)
            exit()
        else:
            cnt += 1
    else:
        print(cnt)
        break

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect
from itertools import accumulate


def zz():
    return list(map(int, sys.stdin.readline().split()))


def z():
    return int(sys.stdin.readline())


def S():
    return sys.stdin.readline()


def C(line):
    return [sys.stdin.readline() for _ in range(line)]


N, M, K = zz()
A = zz()
B = zz()
# 累積和を見てみる
A_sum = [0]
A_sum.extend(list(accumulate(A)))
B_sum = [0]
B_sum.extend(list(accumulate(B)))

# a_idx + b_idx を最大化
# K >= A_sum[a_idx+1] + B_sum[b_idx+1]
a_idx = bisect.bisect(A_sum, K) - 1
# b_tmp = bisect.bisect(A_sum, K)
# ans = max(a_idx+1, b_tmp)
# ans = (a_idx+1)
# print(A_sum)
# print(B_sum)
# print('a_idx', a_idx)
ans = a_idx
if (a_idx == 0):
    b_idx = bisect.bisect(B_sum, K) - 1
    print(b_idx)
    exit()
else:
    for b_idx in range(M+1):
        # print(B_sum[b_idx] + A_sum[a_idx], a_idx, b_idx)
        while (B_sum[b_idx] + A_sum[a_idx] > K):
            a_idx -= 1
            if (a_idx <= 0):
                # print(a_idx, b_idx)
                print(max(ans, 0))
                exit()
        ans = max(ans, a_idx+b_idx)
# print(a_idx, b_idx)

print(max(ans, 0))

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_max = 0
sum = 0
for i in range(n):
  sum += A[i]
  if sum > k:
    sum -= A[i]
    break
  a_max += 1
  
ans = a_max
kotae =ans
j = 0


for i in range(m):
  sum += B[i]
  ans += 1
  while sum > k and j < a_max:
    sum -= A[a_max-1-j]
    ans -= 1
    j += 1
  if sum > k:
    print(kotae)
    exit()
  kotae = max(kotae, ans)
  if a_max-j == 0:
    break
  
print(kotae)

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
count=0
M=0

while M<=k:
  if i<=len(A)-1:
    if min(A[i],B[j])==A[i]:
      M+=A[i]
      if M>k:
        break
      #print(M,A[i],'i=',i)
      if i<len(A)-1:
        i+=1
      count+=1
  else:
    M+=B[j]
    if M>k:
        break
    #print(M,B[j],j)
    j+=1
    count+=1

  if j<=len(B)-1: 
    if min(A[i],B[j])==B[j]:
      M+=B[j]
      if M>k:
        break
      #print(M,B[j],'j=',j)
      if j<len(B)-1:
        j+=1
      count+=1
  else:
    M+=A[i]
    if M>k:
      break
    #print(M,A[i],i)
    i+=1
    count+=1

  if A[i]==B[j]:
    M+=A[i]
    if M>k:
        break
    #print(M,A[i],'i=',i)
    if i<len(A)-1:
      i+=1
    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()))
i,j = 0,0
K = k
a.append(k)
b.append(k)
ans1,ans2 = 0,0
for l in range(n+m):
    if a[i] <= b[j] and a[i] <= k:
        k -= a[i]
        i += 1
        ans1 += 1
    elif a[i] > b[j] and b[j] <= k:
        k -= b[j]
        j += 1
        ans1 += 1
i,j = 0,0
for l in range(n+m):
    if a[i] < b[j] and a[i] <= K:
        K -= a[i]
        i += 1
        ans2 += 1
    elif a[i] >= b[j] and b[j] <= K:
        K -= b[j]
        j += 1
        ans2 += 1
print(ans1) if ans1 >= ans2 else print(ans2)

Submission status: Wrong Answer

Solution code:
import numpy as np
import bisect

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

ac = np.cumsum(a)
bc = np.cumsum(b)
ans = 0

time = 0
ai = 0
bi = 0

# print(ac)
# print(bc)

a_bisect = bisect.bisect_left(ac, k)
b_bisect = bisect.bisect_left(bc, k)
leftTime = 0


if a_bisect < b_bisect:
    leftTime = k - bc[b_bisect - 1]
    ans += b_bisect + bisect.bisect_left(ac, leftTime)
elif a_bisect > b_bisect:
    leftTime = k - ac[a_bisect - 1]
    ans += a_bisect + bisect.bisect_left(bc, leftTime)
else:
    if k - bc[b_bisect - 1] <= k - ac[a_bisect - 1]:
        leftTime = k - bc[b_bisect - 1]
        ans += b_bisect + bisect.bisect_left(ac, leftTime)
    else:
        leftTime = k - ac[a_bisect - 1]
        ans += a_bisect + bisect.bisect_left(bc, leftTime)
if ans > 0:
    ans += 1
print(ans)

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.append(10**9+1)
    b.append(10**9+1)
    a, b = a[::-1], b[::-1]
    sum = 0
    for _ in range(10**9):
        x = a.pop() if a[-1] < b[-1] else b.pop()
        if x > 10**9:
            break
        k -= x
        if k < 0:
            break
        sum += 1
    print(sum)

if __name__ == "__main__":
    main()

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()))
ans = 0
n = 0
m = 0
s = 0
for _ in range(len(A) + len(B)+ 1):
    if n <= len(A)-1 and m <= len(B)-1:
        if A[n] < B[m]:
            s += A[n]
            ans += 1
            n += 1
        else:
            s += B[m]
            ans += 1
            m += 1
    elif n <= len(A) - 1 and m == len(B):
        s += A[n]
        ans += 1
        n += 1    
    elif n == len(A) and m <= len(B)-1:
        s += B[m]
        ans += 1
        m += 1
    elif n == len(A) and m == len(B):
        print(ans)
        exit()
    if s > K:
        print(ans-1)
        exit()
    elif s == K:
        print(ans)
        exit()

Submission status: Wrong Answer

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


ans = 0
for i in range(n + 1):
    A = C
    B = D
    t = 0
    t += sum(A[:i])
    A = C[::-1]
    B = D[::-1]
    if t <= k:
        bnum = i
    else:
        bnum = 0
    while t <= k:
        if len(B) == 0:
            break
        b = B.pop()
        if t + b <= k:
            t += b
            bnum += 1
    ans = max(ans, bnum)

print(ans)

Submission status: Wrong Answer

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

L = []
while a and b:
    if a[0] <=b[0]:
        L.append(a[0])
        a.popleft()
    else:
        L.append(b[0])
        b.popleft()
if a:
    for i in range(len(a)):
        L.append(a[i])
if b:
    for i in range(len(b)):
        L.append(b[i])
#print(L,a,b)
for i in range(len(L)):
    num +=L[i]
    #print(num)
    if num >k:
        print(i)
    elif num == k:
        print(i+1)
        exit()

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
t_sum = 0
cnt = 0
flag = True

for _ in range(500000):
  if A[a] <= B[b]:
    t_sum += A[a]
    cnt += 1
    a += 1
  else:
    t_sum += B[b]
    cnt += 1
    b += 1
  if t_sum > K:
    cnt -= 1
    break
  if a == len(A):
    for _ in range(len(B)+1):
      if b == len(B):
        flag = False
        break
      t_sum += B[b]
      cnt += 1
      b += 1
      if t_sum > K:
        cnt -= 1
        flag = False
        break
  if not flag:
    break
  if b == len(B):
    for _ in range(len(A)+1):
      if a == len(A):
        flag = False
        break
      t_sum += A[a]
      cnt += 1
      if t_sum > K:
        cnt -= 1
        flag = False
        break
  if not flag:
    break
  
  
print(cnt)

Submission status: Wrong Answer

Solution code:
import queue

from collections import deque

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

    BIG = pow(10, 9) + 1

    Aq = deque()
    Bq = deque()

    for i in range(N):
        Aq.append(A[i])

    for i in range(M):
        Bq.append(B[i])

    times = 0
    read_books = 0

    while times < K:
        # print("times {} read {}".format(times, read_books))

        if not Aq and not Bq:
            break

        if not Aq:
            b = Bq.popleft()
            if b+times > K:
                break
            else:
                times += b
                read_books += 1
                continue

        if not Bq:
            a = Aq.popleft()
            if a + times > K:
                break
            else:
                times += a
                read_books += 1
                continue


        A_head = Aq.popleft()
        B_head = Bq.popleft()

        if A_head+times > K and B_head+times > K:
            break

        if A_head < B_head:
            times += A_head
            read_books += 1

            Bq.appendleft(B_head)

        else:
            times += B_head
            read_books += 1
            Aq.appendleft(A_head)



    print(read_books)






     # times = 0
     # read_books = 0
     #
     # while times < K:
     #     if A[0]+times > K and B[0]+times > K:
     #         break
     #
     #     elif A[0] < B[0]:
     #         times += A[0]
     #
     #         if len(A) <= 1:
     #             A[0] = BIG
     #         else:
     #             x = A.pop(0)
     #
     #
     #     elif A[0] >= B[0]:
     #         times += B[0]
     #
     #         if len(B) <= 1:
     #             B[0] = BIG
     #         else:
     #             x = B.pop(0)
     #     elif A[0] == BIG and B[0] == BIG:
     #         break
     #     # else:
     #     #     op = 0
     #     #     # print("error?")
     #
     #     read_books += 1
     #
     #     # print("times {} read {}".format(times,read_books))









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()))
ans1=0
ans2=0
k2=k
while k > 0:
  if a[0] < b[0]:
    if k-a[0] >= 0:
      ans1+=1
      k-=a[0]
      a=a[1:]
      if len(a)==0:
        a.append(10**10)
    else:
      break
  elif a[0] > b[0]:
    if k-b[0] >= 0:
      ans1+=1
      k-=b[0]
      b=b[1:]
      if len(b)==0:
        b.append(10**10)
    else:
      break
  else:
    if k-a[0] >= 0:
      ans1+=1
      k-=a[0]
      a=a[1:]
      if len(a)==0:
        a.append(10**10)
    else:
      break
while k2 > 0:
  if a[0] < b[0]:
    if k2-a[0] >= 0:
      ans2+=1
      k2-=a[0]
      a=a[1:]
      if len(a)==0:
        a.append(10**10)
    else:
      break
  elif a[0] > b[0]:
    if k2-b[0] >= 0:
      ans2+=1
      k2-=b[0]
      b=b[1:]
      if len(b)==0:
        b.append(10**10)
    else:
      break
  else:
    if k2-b[0] >= 0:
      ans2+=1
      k2-=b[0]
      b=b[1:]
      if len(b)==0:
        b.append(10**10)
    else:
      break
print(max(ans1,ans2))

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(99999999999)
b.append(99999999999)
i=0
j=0
time = 0
while time < k:
    if i+j>m+n:
        break
    if a[i] <= b[j] and a[i]+time <= k:
        time +=a[i]
        i+=1
    elif a[i] > b[j] and b[j]+time <= k:
        time+=b[j]
        j+=1
    else:
        break
print(i+j)

Submission status: Wrong Answer

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

a_depth = 0
tmp = 0
for i in range(n):
    if tmp+a[i] <= k:
        tmp += a[i]
        a_depth += 1
    else:
        break
b_depth = 0
tmp = 0
for i in range(m):
    if tmp+b[i] <= k:
        tmp += b[i]
        b_depth += 1
    else:
        break

ans = 0
total = 0
tmp_ans = 0

for i in range(a_depth):
    for j in range(a_depth-i):
        if total+a[j] <= k:
            total += a[j]
            tmp_ans += 1
        else:
            break
    
    for j in range(b_depth):
        if total+b[j] <= k:
            total += b[j]
            tmp_ans += 1
        else:
            break
        
    ans = max(ans, tmp_ans)

print(ans)

Submission status: Wrong Answer

Solution code:
# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


def main():
    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
    res = 0

    isAexist = True
    isBexist = True

    for i in range(N+M):
        if isAexist:
            tA = A[a]
        else:
            tA = 10 ** 9 + 1
        if isBexist:
            tB = B[b]
        else:
            tB = 10 ** 9 + 1
        if (tA <= tB) & isAexist:
            if time + tA <= K:
                time += tA
                a += 1
                res += 1
                if a == N:
                    isAexist = False
        elif (tA >= tB) & isBexist:
            if time + tB <= K:
                time += tB
                b += 1
                res += 1
                if b == M:
                    isBexist = False
        # print(res,time,a,b)
        if isAexist:
            if time + A[a] > K:
                isAexist = False
        if isBexist:
            if time + B[b] > K:
                isBexist = False
        if (not isAexist) & (not isBexist):
            break

    print(res)



main()

Submission status: Wrong Answer

Solution code:
#C - Tsundoku

n,m,k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
minutes = 0
ct = 0
while minutes < k:
    if n >0 and m>0:
        if min(A[0],B[0]) == A[0]:
            if minutes + A[0] <=k:
                n -= 1
                minutes += A[0]
                A.remove(A[0])
                ct +=1
            else:
                break
        elif min(A[0],B[0]) == B[0]:
            if minutes + B[0] <=k:
                m -= 1
                minutes += B[0]
                B.remove(B[0])
                ct +=1
            else:
                break
    elif n >0:
        if minutes + A[0] <=k:
                n -= 1
                minutes += A[0]
                A.remove(A[0])
                ct +=1
        else:
            break
    elif m >0:
        if minutes + B[0] <=k:
                m -= 1
                minutes += B[0]
                B.remove(B[0])
                ct +=1
        else:
            break
    else:
        break

print(ct)

Submission status: Wrong Answer

Solution code:
n,m,k=[int(x) for x in input().split()]
a=[int(x) for x in input().split()]
b=[int(x) for x in input().split()]
t=0
if a[0]>k and b[0]>k:
  print(0)
else:
  flag=False
  count=0
  while t<=k:
    if a==[] and b==[]:
      break
    elif a==[]:
      t+=b[0]
      count+=1
      if t>k:
        t-=b[0]
        count-=1
        flag=True
      else:
        del b[0]
    elif b==[]:
      t+=a[0]
      count+=1
      if t>k:
        t-=a[0]
        count-=1
        flag=True
      else:
        del a[0]
    elif a[0]<=b[0] or b==[]:
      t+=a[0]
      count+=1
      if t>k:
        t-=a[0]
        count-=1
        flag=True
      else:
        del a[0]
    elif a==[] or a[0]>b[0]:
      t+=b[0]
      count+=1
      if t>k:
        t-=b[0]
        count-=1
        flag=True
      else:
        del b[0]
    if flag:
      break
  print(count)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**9)

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

ans=0
count=0
i,j=0,0
while ans<k:
  if i > n-1:
    num=b[j]
  elif j > m-1:
    num=a[i]
  else:
    num=min(a[i],b[j])
    if num==a[i]:
      i+=1
      count+=1
      ans+=num
    else:
      j+=1
      count+=1
      ans+=num

print(count-1)

Submission status: Wrong Answer

Solution code:

def main():
    n, m, k = map(int, input().split())
    aa = list(map(int, input().split()))
    bb = list(map(int, input().split()))
    a_num = 0
    b_num = 0
    time_sum = 0
    counter = 0
    if bb[b_num] >= aa[a_num]:
        if k < aa[a_num]:
            return counter
    if bb[b_num] <= aa[a_num]:
        if k < bb[b_num]:
            return counter

    for i in range(n+m):
        if len(bb) == b_num and len(aa) == a_num:
            print('test')
            break
        if len(bb) == b_num:
            time_sum += aa[a_num]
            a_num += 1
        elif len(aa) == a_num:
            time_sum += bb[b_num]
            b_num += 1
        elif aa[a_num] > bb[b_num]:
            time_sum += bb[b_num]
            b_num += 1
        else:
            time_sum += aa[a_num]
            a_num += 1

        if time_sum > k:
            break
        counter += 1

    return counter


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

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()))
time = 0
ans_list = []
a.insert(0,0)
for i in range(n+1):
  time = time + a[i]
  book = i
  if time <= k:
    ans_list.append(book)
  for j in range(m):
    time = time + b[j]
    book = book + 1
    if time <= k:
      ans_list.append(book)
  time = 0
if len(ans_list) == 0:
  ans = n + m
else:
  ans = max(ans_list)
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

result = 0
time = 0

while True:
    if a_i >= n and b_i >= m:
        break
    elif a_i >= n:
        if time + b[b_i] <= k:
            time += b[b_i]
            result += 1
            b_i += 1
            continue
        else:
            break
    elif b_i >= m:
        if time + a[a_i] <= k:
            time += a[a_i]
            result += 1
            a_i += 1
            continue
        else:
            break
    elif a[a_i] <= b[b_i]:
        if time + a[a_i] <= k:
            time += a[a_i]
            result += 1
            a_i += 1
            continue
        else:
            break
    else:
        if time + b[b_i] <= k:
            time += b[b_i]
            result += 1
            b_i += 1
            continue

print(result)

Submission status: Wrong Answer

Solution code:

def solve():
    num = len(AB)
#    print("num\t" + str(num))
    total = 0
    cnt = 0
    for i in range(num):
        if total+ AB[i] <= K:
            cnt += 1
            total += AB[i]
        else:
            print(cnt)
            exit()
    print(cnt)

if __name__=="__main__":
    N,M,K = list(map(int, input().split()))
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    AB = A+B
    AB.sort()
#    print(AB)
    solve()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A.append(99999)
B.append(99999)
Sum = 0
i = 0
j = 0
while True:
  if A[i] <= B[j] and Sum + A[i] <= K:
    Sum += A[i]
    i += 1
  elif A[i] > B[j] and Sum + B[j] <= K:
    Sum += B[j]
    j += 1
  else:
    break
if Sum >= 1000000000:
  print(0)
else:
  print(i + j)

Submission status: Wrong Answer

Solution code:
from collections import deque
n,m,k = map(int, input().split())
a = list(map(int, list(input().split())))
b = list(map(int, list(input().split())))
t = 0
c = 0
while True:
    if c < n+m:
        if len(b) == 0 and t + a[0] <= k:
            t = t + a[0]
            a = a[1:]
            c = c + 1
        elif len(a) == 0 and t + b[0] <= k:
            t = t + b[0]
            b = b[1:]
            c = c + 1
        elif len(a) > 0 and len(b) > 0:
            if a[0] <= b[0] and a[0] <= 1000000000 and b[0] <= 1000000000 and t + a[0] <= k:
                t = t + a[0]
                a = a[1:]
                c = c + 1
            elif a[0] > b[0] and a[0] <= 1000000000 and b[0] <= 1000000000 and t + b[0] <= k:
                t = t + b[0]
                b = b[1:]
                c = c + 1
            else:
                break
        else:
            break
    else:
        break
print(c)

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.append(10**9+1)
    b.append(10**9+1)
    a, b = a[::-1], b[::-1]
    sum = 0
    for _ in range(400001):
        x = a.pop() if a[-1] < b[-1] else b.pop()
        if x > 10**9:
            break
        k -= x
        if k < 0:
            break
        sum += 1
    print(sum)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys, math
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

N, M, K = rl()
A = rl()
B = rl()

s = 0
for i, b in enumerate(B):
	s += b
	B[i] = s

import bisect

ans = 0
s = 0
for i, a in enumerate(A):
	s += a
	if s > K:
		break
	j = bisect.bisect_right(B, K-s)
	#print(i, j)
	n = i+1 + j
	ans = max(ans, n)
print(ans)