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 = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]
B = [int(_) for _ in input().split()]

v = 0
ans = 0
for i in range(N):
    if v + A[i] <= K:
        v += A[i]
    else:
        mi = i-1
        break
else:
    mi = N-1

for j in range(M):
    while mi > -1 and v + B[j] > K:
        v -= A[mi]
        mi -= 1
    if v + B[j] <= K:
        v += B[j]
        ans = max(ans, mi+1+ j+1)

print(ans)

Submission status: Wrong Answer

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

cnt = 0
time = 0
A_s = sum(A)
B_s = sum(B)

if A_s + B_s <= k:
  print(len(A)+len(B))
elif A[0] > k and B[0] > k:
  print(0)
else:
  while time <= k:
      if A[0] >= B[0]:
          time += B[0]
          del B[0]
          cnt += 1
          if len(B) == 0:
              B.append(10000000000)
      else:
         time += A[0]
         del A[0]
         cnt += 1
         if len(A) == 0:
             A.append(10000000000)
  print(cnt-1)

Submission status: Wrong Answer

Solution code:
import bisect

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
cuma, cumb = [0], [0]
for i in range(1, n+1):
    cuma.append(cuma[i-1] + a[i-1])
for i in range(1, m+1):
    cumb.append(cumb[i-1] + b[i-1])
ans = [0]
for i in range(n+1):
    if cuma[i] <= k:
        t = k - cuma[i]
        if t >= cumb[-1]:
            j = m + 1
        else:
            j = bisect.bisect_left(cumb, t)
        ans.append(i+j-1)
print(max(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()))

t = 0
m = 0
cnt = 0

if (sum(A) + sum(B)) <= K:
    print(N + M)
    sys.exit()
while True:
    if t > K:
        print(cnt-1)
        sys.exit()
    elif t == K:
        print(cnt)
        sys.exit()

    if len(A) == 0:
        m = B[0]
    elif len(B) == 0:
        m = A[0]
    else:
        m = min(A[0], B[0])

    t += m
    cnt += 1


    if len(A) != 0 and m == A[0]:
        A.pop(0)
    elif len(B) != 0 and m == B[0]:
        B.pop(0)

Submission status: Wrong Answer

Solution code:
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

# import fractions

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, M, K = il()
    A = deque(il())
    B = deque(il())
    A.append(MAX)
    B.append(MAX)

    time, ret = 0, 0
    while True:
        if len(A) > 0 and A[0] <= B[0] and time + A[0] <= K:
            time += A[0]
            A.popleft()
            ret += 1
        elif len(B) > 0 and B[0] <= A[0] and time + B[0] <= K:
            time += B[0]
            B.popleft()
            ret += 1
        elif len(B) == 0 and time + A[0] <= K:
            time += A[0]
            A.popleft()
            ret += 1
        elif len(A) == 0 and time + B[0] <= K:
            time += B[0]
            A.popleft()
            ret += 1
        else:
            break
    print(ret)


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

i,j = 0,0

cnt = 0

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

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

print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import deque
from sys import stdin
input = stdin.readline


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

  num_book = 0
  ac_A = [0]*(len(A)+1)
  for i, a in enumerate(A):
    ac_A[i+1] = ac_A[i] + a

  ac_B = [0]*(len(B)+1)
  for i, b in enumerate(B):
    ac_B[i+1] = ac_B[i] + b

  # print(ac_A)
  # print(ac_B)

  ai = 0
  bi = 0
  while (ai < len(A) or bi < len(B)):
    if ai >= len(A):
      bi += 1
    elif bi >= len(B):
      ai += 1
    elif (ac_A[ai+1] < ac_B[bi+1]):
      ai += 1
    else:
      bi += 1

    if K >= ac_A[ai] + ac_B[bi]:
      num_book += 1
    else:
      break

  print(num_book)


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 = A[0]
if a <= K:
    max = 1
else:
    max = 0
for i in range(1,N):
    a += A[i]
    A[i] = a
    if a <= K:
        max = i+1
b = B[0]
if max >= 1:
    L = K-A[max-1]
else:
    L = K
if b <= L:
    m = 1
else:
    m = 0
for i in range(1,M):
    b += B[i]
    B[i] = b
    if b <= L:
        m = i+1
ans = max+m
if max == 0 and m == 0:
    print(0)
else:
    while(max > 0 and m<M):
        max -= 1
        L = K-A[max]
        while(m<M and B[m]<=L):
                m += 1
        if max + m+1 > ans:
            ans = max+1+m
    print(ans)

Submission status: Wrong Answer

Solution code:
i = list(map(int, input().split()))
n=i[0]
m=i[1]
k=i[2]
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a=b=0 #それぞれの読んだ数
cal=0 #読んだ時間
while True:
  if a!=n and b!=m:
      if A[a]<B[b]:
          cal+=A[a]
          a+=1
          if cal>k:
              a-=1
              break
      elif B[b]<A[a]:
          cal+=B[b]
          b+=1
          if cal>k:
              b-=1
              break
      elif B[b]==A[a]:
          cal+=A[a]
          a+=1
          if cal>k:
              a-=1
              break
  elif a==n and b==m:
    break
  elif a==n:
      cal+=B[b]
      b+=1
      if cal>k:
          b-=1
          break
  elif b==m:
      cal+=A[a]
      a+=1
      if cal>k:
          a-=1
          break
print(a+b)

Submission status: Wrong Answer

Solution code:
try:
  # Python3 program to count distinct 
# divisors of a given number n 

  def SieveOfEratosthenes(n, prime,primesquare, a): 
      # Create a boolean array "prime[0..n]" 
      # and initialize all entries it as 
      # true. A value in prime[i] will finally 
      # be false if i is not a prime, else true. 
      for i in range(2,n+1): 
          prime[i] = True

      # Create a boolean array "primesquare[0..n*n+1]" 
      # and initialize all entries it as false. 
      # A value in squareprime[i] will finally be 
      # true if i is square of prime, else false. 
      for i in range((n * n + 1)+1): 
          primesquare[i] = False

      # 1 is not a prime number 
      prime[1] = False

      p = 2
      while(p * p <= n): 
          # If prime[p] is not changed, 
          # then it is a prime 
          if (prime[p] == True): 
              # Update all multiples of p 
              i = p * 2
              while(i <= n): 
                  prime[i] = False
                  i += p 
          p+=1


      j = 0
      for p in range(2,n+1): 
          if (prime[p]==True): 
              # Storing primes in an array 
              a[j] = p 

              # Update value in primesquare[p*p], 
              # if p is prime. 
              primesquare[p * p] = True
              j+=1

  # Function to count divisors 
  def countDivisors(n): 
      # If number is 1, then it will 
      # have only 1 as a factor. So, 
      # total factors will be 1. 
      if (n == 1): 
          return 1

      prime = [False]*(n + 2) 
      primesquare = [False]*(n * n + 2) 

      # for storing primes upto n 
      a = [0]*n 

      # Calling SieveOfEratosthenes to 
      # store prime factors of n and to 
      # store square of prime factors of n 
      SieveOfEratosthenes(n, prime, primesquare, a) 

      # ans will contain total 
      # number of distinct divisors 
      ans = 1

      # Loop for counting factors of n 
      i=0
      while(1): 
          # a[i] is not less than cube root n 
          if(a[i] * a[i] * a[i] > n): 
              break

          # Calculating power of a[i] in n. 
          cnt = 1 # cnt is power of 
                  # prime a[i] in n. 
          while (n % a[i] == 0): # if a[i] is a factor of n 
              n = n / a[i] 
              cnt = cnt + 1 # incrementing power 

          # Calculating number of divisors 
          # If n = a^p * b^q then total 
          # divisors of n are (p+1)*(q+1) 
          ans = ans * cnt 
          i+=1

      # if a[i] is greater than 
      # cube root of n 

      n=int(n) 
      # First case 
      if (prime[n]==True): 
          ans = ans * 2

      # Second case 
      elif (primesquare[n]==True): 
          ans = ans * 3

      # Third casse 
      elif (n != 1): 
          ans = ans * 4

      return ans # Total divisors 

  n=int(input())
  dp=[]
  for i in range(1,n+1):
      dp.append(countDivisors(i))
  ans=0
  for i in range(len(dp)):
      ans+=(dp[i]*(i+1))
  print(ans)
except:
  pass

Submission status: Wrong Answer

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

while sum(sum_time) <= k:
    if len(a) == 0 and len(b) == 0:
        break
    elif len(a) == 0:
        sum_time.append(b.pop())
    elif len(b) == 0:
        sum_time.append(a.pop())
    elif a[-1] <= b[-1]:
        sum_time.append(a.pop())
    else:
        sum_time.append(b.pop())

if sum(sum_time) > k:
    sum_time.pop()

print(len(sum_time)-1)

Submission status: Wrong Answer

Solution code:
import math
import sys
from collections import deque

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


count = 0
time = 0
#もし先にどっちかの玉が尽きた時の問題。
for i in range(10**6):
    #本が尽きていない。
    if len(A) != 0 and len(B) != 0:

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

        elif A[0] > B[0]:
            time = time + B[0]
            if time <= K:
                count = count + 1
                B.popleft()
        else:
            time = time + A[0]
            if time <= K:
                count = count + 1
                A.popleft()
    else:
        #どっかの本が尽きている。
        if len(A) == 0 and len(B) != 0:
            time = time + B[0]
            if time <= K:
                count = count + 1
                B.popleft()
        elif len(A) != 0 and len(B) == 0:
            time = time +A[0]
            if time <= K:
                count = count + 1
                A.popleft()
        elif len(A) == 0 and len(B) == 0:
            print(count)
            sys.exit()
               


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

c = 0
a_idx = 0
b_idx = 0
for i in range(len(a)+len(b)):
  if a_idx == n and b_idx == m:
    break
  elif a_idx < n and b_idx == m:
    if k >= a[a_idx]:
      k -= a[a_idx]
      a_idx += 1
      c += 1
    else:
      break
  elif a_idx == n and b_idx < m:
    if k >= b[b_idx]:
      k -= b[b_idx]
      b_idx += 1
      c += 1
    else:
      break
  else:
    if a[a_idx] >= b[b_idx]:
      if k >= b[b_idx]:
        k -= b[b_idx]
        b_idx += 1
        c += 1
      else:
        break
    else:
      if k >= a[a_idx]:
        k -= a[a_idx]
        a_idx += 1
        c += 1
      else:
        break
print(c)

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(main(n, m, k, a_n, b_n))

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
from itertools import accumulate
from bisect import bisect_left

sys.setrecursionlimit(4100000)

def main():
    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = [0] + list(accumulate(A))
    D = [0] + list(accumulate(B))
    if sum(A) + sum(B) <= K:
        print(N+M)
        exit()
    
    cnt = 0
    for i in range(N+1):
        tmp_cnt = i
        tmp_ans = C[i]
        if tmp_ans > K:
            break
        tmp_index = bisect_left(D, K-tmp_ans) -1
        tmp_cnt += tmp_index
        cnt = max(cnt,tmp_cnt)



    print(cnt)





if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import deque

N, M, K = map(int, input().split())
alist = list(map(int, input().split()))
blist = list(map(int, input().split()))
aq = deque()
bq = deque()
res=0

for i in range(0,N):
  aq.append(alist[i])

for j in range(0,M):
  bq.append(blist[j])

while(0<K):
  if(len(aq)!=0):
    a=aq.popleft()
  else:
    a=10**9
  if(len(bq)!=0):
    b=bq.popleft()
  else:
    b=10**9
  if(a<b):
    res+=1
    K-=a
    if(K<0):
      res-=1
      break
    bq.appendleft(b)
  elif(b<a):
    res+=1
    K-=b
    if(K<0):
      res-=1
      break
    aq.appendleft(a)
  elif(a==b):
    res+=1  
    K-=a
    if(K<0):
      res-=1
      break
    res+=1
    K-=b
    if(K<0):
      res-=1
      break
print(res)

Submission status: Wrong Answer

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

a_list=[int(i) for i in input().split()]
b_list=[int(i) for i in input().split()]
#print(a_list)
#print(b_list)


#時間内に全部読める
if sum(a_list)+sum(b_list)<=k:
    ans=m+n

#時間内に読めない
else:
    t=0
    count=0
    
    while t<=k:
        
        if a_list==[]:
            t+=b_list[0]
            del b_list[0]
            count+=1
            
        elif  b_list==[]:
            t+=a_list[0]
            del a_list[0]
            count+=1
            
        elif a_list[0] <  b_list[0]:
            t+=a_list[0]
            del a_list[0]
            count+=1
            
        else:
            t+=b_list[0]
            del b_list[0]
            count+=1
    
    ans=count-1
        
    

    
    
    
print(ans)

Submission status: Wrong Answer

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

a.append(pow(10,10))
b.append(pow(10,10))

ans = 0
ai = 0
bi = 0

while True:
  t = 0
  if a[ai] > b[bi]:
    t = b[bi]
    bi += 1
  else:
    t = a[ai]
    ai += 1
  if k >= t:
    k -= t
    ans += 1
    if k == 0:
      break
  else:
    break

print(str(ans))

Submission status: Wrong Answer

Solution code:
import bisect

N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
tmp = 0
for i in range(N):
    A[i], tmp = A[i] + tmp, tmp + A[i]

tmp = 0
for i in range(M):
    B[i], tmp = B[i] + tmp, tmp + B[i]

re = 0
for i, element in enumerate(A):
    K_tmp = K - element
    if K_tmp < 0:
        pass
    else:
        idx_B = bisect.bisect_right(B, K_tmp)
        re_tmp = i + 1 + idx_B
        re = max(re, re_tmp)
print(re)

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
from math import floor, sqrt, factorial, hypot, log  # log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter, defaultdict, deque
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint


def ceil(a, b): return (a + b - 1) // b


inf = float('inf')
mod = 10 ** 9 + 7


def pprint(*A):
    for a in A:     print(*a, sep='\n')


def INT_(n): return int(n) - 1


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


def MF(): return map(float, input().split())


def MI_(): return map(INT_, input().split())


def LI(): return list(MI())


def LI_(): return [int(x) - 1 for x in input().split()]


def LF(): return list(MF())


def LIN(n: int): return [I() for _ in range(n)]


def LLIN(n: int): return [LI() for _ in range(n)]


def LLIN_(n: int): return [LI_() for _ in range(n)]


def LLI(): return [list(map(int, l.split())) for l in input()]


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


def F(): return float(input())


def ST(): return input().replace('\n', '')


def main():
    N, M, K = MI()
    A = LI()
    B = LI()
    ans = 0
    total = 0
    anow = -1
    for a in A:
        if a + total <= K:
            ans += 1
            total += a
            anow += 1
        else:
            break
    maxans = ans
    for b in B:
        total += b
        while total > K:
            if anow == -1:
                break
            total -= A[anow]
            anow -= 1
            ans -= 1
        ans += 1
        maxans = max(maxans, ans)
    print(maxans)

if __name__ == '__main__':
    main()

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()]
y=0
z=0
a.append(1000000001)
b.append(1000000001)
while int(a[y])<=k or int(b[z])<=k:
    if int(a[y])<int(b[z]):
        k -= int(a[y])
        y+=1
    elif int(a[y])>int(b[z]):
        k -= int(b[z])
        z+=1
else:
    print(y+z)

Submission status: Wrong Answer

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

    if sum(a) + sum(b) <= k: return n + m
    cnt = 0
    su = 0
    while su <= k:
        if a and b:
            su += min(a[0], b[0])
            if a[0]<=b[0]:
                a.pop(0)
            else:
                b.pop(0)
            cnt += 1
        elif not a and not b:
            break
        elif not a:
            su += b[0]
            b.pop(0)
            cnt += 1
        elif not b:
            su += a[0]
            a.pop(0)
            cnt += 1

    return cnt-1


print(solve())

Submission status: Wrong Answer

Solution code:
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
A.append(10**9)
B.append(10**9)
cnt2 = 0
cnt = 0
for i in range(400000):
    if A[0] < B[0]:
        cnt2 += A[0]
        del A[0]
    else:
        cnt2 += B[0]
        del B[0]
    if cnt2 <= K:
        cnt += 1
    else:
        break
print(cnt)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
import sys
import bisect
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=max(len(a),len(b))
if len(a)==c:
    b+=[0]*(c-len(b))
else:
    a+=[0]*(c-len(a))
l=[]
for A,B in zip(a,b):
    l.append(min(A,B))
    l.append(max(A,B))
cumsum=list(accumulate(l))
print(bisect.bisect_left(cumsum,k))

Submission status: Wrong Answer

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

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

from collections import deque
d = deque()

buf_K = K
ans = 0
for i in range(N):
    if buf_K >= A[i]:
        buf_K -= A[i]
        d.append(A[i])
        ans += 1
    else:
        break
max_num = ans

for j in range(M):
    if buf_K >= B[j]:
        buf_K -= B[j]
        ans += 1
        if ans > max_num:
            max_num = ans
    else:
        flag = True
        while d:
            buf_K += d.popleft()
            ans -= 1
            if buf_K >= B[j]:
                buf_K -= B[j]
                ans += 1
                if ans > max_num:
                    max_num = ans
                flag = False
                break
        if flag:
            break

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

flag = True
minute = 0
ans = 0
ind = 0

while flag:
    
    targetA = 10**10
    targetB = 10**10
    
    if a:
        targetA = a[ind]
    if b:
        targetB = b[ind]

    
    if targetA <= targetB:
        minute += targetA
        del a[ind]
    else:
        minute += targetB
        del b[ind]
    
    

    if k == minute:
        ans += 1
        flag = False
        break
    
    if k < minute:
        flag = False
        break
    
    ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
# 幅優先探索（行きがけ）
import collections
import sys
import copy
import re
import bisect


def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())


def main():
    N, M, K = LI()
    AArray = LI()
    BArray = LI()

    aSum = [AArray[0]]
    bSum = [BArray[0]]

    cnt = 0

    for i in range(1, N):
        aSum.append(aSum[i-1]+AArray[i])
    for i in range(1, M):
        bSum.append(bSum[i-1]+BArray[i])

    for i in range(N):
        a = aSum[i]
        if a > K:
            break
        sa = K-a
        b = bisect.bisect_right(bSum, sa)
        cnt = max(cnt, i+1+b)

    # while K > 0 and (len(AArray) > 0 or len(BArray) > 0):
    #     if len(AArray) > 0 and len(BArray) > 0:
    #         if AArray[0] >= BArray[0]:
    #             b = BArray.pop(0)
    #             if K-b >= 0:
    #                 K -= b
    #                 cnt += 1
    #             else:
    #                 break
    #         elif AArray[0] < BArray[0]:
    #             a = AArray.pop(0)
    #             if K-a >= 0:
    #                 K -= a
    #                 cnt += 1
    #             else:
    #                 break
    #     elif len(AArray) == 0:
    #         b = BArray.pop(0)
    #         if K-b >= 0:
    #             K -= b
    #             cnt += 1
    #         else:
    #             break
    #     else:
    #         a = AArray.pop(0)
    #         if K-a >= 0:
    #             K -= a
    #             cnt += 1
    #         else:
    #             break

    print(cnt)


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


time = 0
i=0
k=0

if sum(A)+sum(B)<K:
    print(M+N)
    exit()


while True:
    
    if i>=N and not k>=M:
        time += B[k]
        if time >=K:
            print(i+k)
            exit()
        k+=1
    elif k>=M and not i>=N:
        time += A[i]
        if time >=K:
            print(i+k)
            exit()
        i += 1
    
    else :
        if A[i]>=B[k]:
            time += B[k]
            if time >=K:
                print(i+k)
                exit()
            k+=1

        else:
            time += A[i]
            if time >=K:
                print(i+k)
                exit()
            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()))

n = 0
m = 0
ans = 0
while K >= 0:
  if K == 0:
    print(ans)
    exit()
  if n < N and m < M:
    if A[n] > B[m]:
      K = K - B[m]
      m += 1
    else:
      K = K - A[n]
      n += 1
  elif n < N and m >= M:
    K = K - A[n]
    n += 1
  elif n >= N and m < M:
    K = K - B[m]
    m += 1
  else:
    print(ans)
    exit()

  if K >= 0:
    ans += 1
  else:
    print(ans)
    exit()

Submission status: Wrong Answer

Solution code:
import sys
import copy
import math
import bisect
import pprint
import bisect
from functools import reduce
from copy import deepcopy
from collections import deque
from decimal import *


import math

import collections


def calcTime(indexA ,indexB,sumTime,co):
    sys.setrecursionlimit(10 ** 9 +1)
    A = 0
    B = 0
    global count
    if indexA+1 < n and sumTime+a[indexA+1] <=k:
        A = calcTime(indexA+1,indexB,sumTime+a[indexA+1],co+1)
        if count < co+1:
            count +=1
    if indexB+1 < m and sumTime+b[indexB+1] <=k:
        B = calcTime(indexA,indexB+1,sumTime+b[indexB+1],co+1)
        if count < co+1:
            count +=1


if __name__ == '__main__':
    n, m,k = map(int, input().split())
    a = [int(i) for i in input().split()]
    b = [int(i) for i in input().split()]
    global count
    count = 0
    calcTime(-1,-1,0,0)

    print(count)

Submission status: Wrong Answer

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

A_np = np.array(A)
B_np = np.array(B)

C_np = np.append(A_np,B_np)
C_np = np.sort(C_np)

x = 0
for i in range(len(C_np)):
    if K > x + C_np[i]:
        x += 1
    else:
        break
print(x)

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10000000)

def whichDesk(a, b):
    if len(a) == 0:
        return 2
    elif len(b) == 0:
        return 1
    elif a[0] >= b[0]:
        return 2
    elif a[0] < b[0]:
        return 1

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

t = 0
cnt = 0

while t <= k and (len(a) > 0 or len(b) > 0):
    if whichDesk(a, b) == 2:
        t += b[0]
        b.pop(0)
    else:
        t += a[0]
        a.pop(0)
    if t <= k:
        cnt += 1

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

a.append(10 ** 10)
b.append(10 ** 10)
na = a.popleft()
nb = b.popleft()

cnt = 0
min = 0
while min <= k:
    if na <= nb:
        cnt += 1
        min += na
        na = a.popleft()
    else:
        cnt += 1
        min += nb
        nb = b.popleft()
    if na == 10 ** 10 and nb == 10 ** 10:
        cnt += 1
        break
print(cnt-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()))


def answer(A,B):
    count=0
    time=0
    
    if sum(A)+sum(B)<k:
        return len(A)+len(B)
    
    elif k<min(A[0],B[0]):
        return 0
    
    else:
        while time<k:
            if len(A)!=0 and len(B)!=0:
                if A[0]>=B[0]:
                    time+=B.pop(0)
                    count+=1
                elif B[0]>A[0]:
                    time+=A.pop(0)
                    count+=1
            elif len(A)==0 and len(B)!=0:
                time+=B.pop(0)
                count+=1
            elif len(B)==0 and len(A)!=0:
                time+=A.pop(0)
                count+=1
            else:
                break
    return count-1


print(answer(A,B))

Submission status: Wrong Answer

Solution code:
import math
import sys
from collections import deque

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


count = 0
time = 0
#もし先にどっちかの玉が尽きた時の問題。
for i in range(400001):
    #本が尽きていない。
    if len(A) != 0 and len(B) != 0:

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

        elif A[0] > B[0]:
            time = time + B[0]
            if time <= K:
                count = count + 1
                B.popleft()
        else:
            time = time + A[0]
            if time <= K:
                count = count + 1
                A.popleft()
    else:
        #どっかの本が尽きている。
        if len(A) == 0 and len(B) != 0:
            time = time + B[0]
            if time <= K:
                count = count + 1
                B.popleft()
        elif len(A) != 0 and len(B) == 0:
            time = time +A[0]
            if time <= K:
                count = count + 1
                A.popleft()
        elif len(A) == 0 and len(B) == 0:
            print(count)
            sys.exit()
               


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_i, b_i = 0, 0
cnt = 0

while a_i < len(a) and b_i < len(b):
    if a[a_i] <= b[b_i]:
        k -= a[a_i]
        a_i += 1
    else:
        k -= b[b_i]
        b_i += 1

    if k < 0:
        print(cnt)
        exit()
    else:
        cnt += 1

while a_i < len(a):
    k -= a[a_i]
    if k < 0:
        print(cnt)
        exit()
    else:
        cnt += 1
        a_i += 1

while b_i < len(b):
    k -= b[b_i]
    if k < 0:
        print(cnt)
        exit()
    else:
        cnt += 1
        b_i += 1

print(cnt)