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:
# -*- coding: utf-8 -*-
n, m, k = map(int, input().split())

alist = input().split()
blist = input().split()

work = k
acount = 0
while (acount < n) and (work >= int(alist[acount])):
    work -= int(alist[acount])
    acount += 1

maxCount = acount
bCount = 0
for num in range(0, acount):
    if (num > 1):
        work += int(alist[acount-num])

    while (bCount < m) and (work >= int(blist[bCount])):
        work -= int(blist[bCount])
        bCount += 1
    maxCount = max(maxCount, acount-num+bCount)




print(maxCount)

Submission status: Wrong Answer

Solution code:
a = [input() for l in range(0,3)]

a1 = [int(p) for p in a[0].split()]
a2 = [int(p) for p in a[1].split()]
a3 = [int(p) for p in a[2].split()]
a4 = a2 + a3

b = sorted(a4)

c = 0
for i in range(0,len(b)):
    c = c + b[i]

if c <= a1[2]:
    print(len(b))
else:
    s = 0
    t = 0
    while s <= a1[2] and t < len(b):
        s = s + b[t]
        t = t + 1
    print(t-1)

Submission status: Wrong Answer

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

t1=0
count1=0
count2=0
t2=0

for i in range(n):
    t1 += a[i]
    if t1>k:
        break
    count1 += 1
if t1<k:
    for j in range(m):
        t1+=b[j]
        if t1>k:
            break
        count1+=1

for i in range(m):
    t2+=b[i]
    if t2>k:
        break
    count2 += 1
if t2<k:
    for j in range(n):
        t2+=a[j]
        if t2>k:
            break
        count2+=1

i=0
j=0
count = 0 
while k>0:
    if i==n:
        k-=b[j]
        j+=1
    elif j==m:
        k-=a[i]
        i+=1
    elif a[i]>b[j]:
        k-=b[j]
        j+=1
    else:
        k-=a[i]
        i+=1
    if k>=0:
        count+=1
print(max(count1,count2,count))

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

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

t = 0
i = 0
j = 0
ans = 0

while t < k:
    if a == []:
        t += b[-1]
        b.pop()
    elif b == []:
        t += a[-1]
        a.pop()
    else:
        t += min(a[-1], b[-1])
        if a[-1] <= b[-1]:
            a.pop()
        else:
            b.pop()
    if t <= k:
        ans += 1
    if a == [] and b == []:
        break
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()))
acur = 0
acurmax = len(a)-1
bcur = 0
bcurmax = len(b)-1
minute = 0
if k < min([a[0],b[0]]):
    print(0)
    sys.exit()
while minute <= k:
    if (acur > acurmax) & (bcur > bcurmax):
        acur += 1
        break
    elif (acur <= acurmax) & (bcur <= bcurmax):
        if a[acur] <= b[bcur]:
            minute += a[acur]
            acur += 1
        else:
            minute += b[bcur]
            bcur += 1
    elif acur > acurmax:
        minute += b[bcur]
        bcur += 1
    else:
        minute += a[acur]
        acur += 1

print(acur+bcur-1)

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    n, m, k = map(int, input().strip().split())
    a = list(map(int, input().strip().split()))
    b = list(map(int, input().strip().split()))

    min = 0
    a_count = 0
    for i, a_min in enumerate(a):
        if a_min + min <= k:
            min += a_min
            a_count += 1
        else:
            break
    b_count = 0

    for i, b_min in enumerate(b):
        if b_min + min <= k:
            min += b_min
            b_count += 1
        else:
            break

    max_count = a_count + b_count
    if not max_count == n + m:
        for i in range(a_count, 0, -1):
            min -= a[i - 1]
            a_count -= 1
            while b_count < len(b) and min + b[b_count] < k:
                min += b[b_count]
                b_count += 1
            if a_count + b_count > max_count:
                max_count = a_count + b_count
    print(max_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()))
l=0
i=0
v=0
if len(a)>len(b):
    for e in range(len(a)-len(b)):
        b.append(0)
if len(a)<len(b):
    for e in range(len(b)-len(a)):
        a.append(0)
 
while l<k:
    #print(i," ",l,' ',v)
    l+=a[i]
    v+=1
    if l<k and l+b[i]<k and b[i]>0:
        l+=b[i]
        v+=1
    elif l>k:
        l=l-a[i]
        v-=1
        break
    if b[i]==0:break
    
    i+=1
    if i>=len(a):break
print(v)

Submission status: Wrong Answer

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

i, j = 0, 0
suma, sumb = 0, 0

while True:
    if k - suma >= a[i]:
        suma += a[i]
        i += 1

    if i == len(a):
        break
    elif k - suma < a[i]:
        break

while True:
    if k - sumb >= b[j]:
        sumb += b[j]
        j += 1
    
    if j == len(b):
        break
    if k - sumb< b[j]:
        break



maxbooks = 0
for x in range(i-1, -1, -1):
    for y in range(j-1, -1, -1):
        if sum(a[0:x+1]) + sum(b[0:y+1]) <= k:
            books = x + y + 2
            maxbooks = max(maxbooks, books)
        else:
            print(x,y)
print(maxbooks)

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 which_time():
    if not A:
        if not B:
            return 'err'
        else:
            return 'b'
    if not B:
        if not A:
            return 'err'
        else:
            return 'a'
    return 'a' if A[0] <= B[0] else 'b'


ans = 0

while True:
    choice = which_time()
    if choice == 'err':
        break

    if choice == 'a':
        K -= A[0]
        if K < 0:
            break
        ans += 1
        A.pop(0)
    else:
        K -= B[0]
        if K < 0:
            break
        ans += 1
        B.pop(0)

print(ans)

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]"):
    candidateA = []
    weightA = 0
    tmp_A = N
    for idx, a in enumerate(A):
        if weightA + a > K:
            tmp_A = idx
            break
        else:
            weightA += a
    candidateA = A[:tmp_A]
    max_count = current_count = len(candidateA)

    candidateB = []
    weightB = 0
    terminated = False
    for b in B:
        if terminated == True and weightA + weightB > K:
            break


        if weightA + weightB + b <= K:
            weightB += b
            candidateB.append(b)
            current_count += 1

        if len(candidateA)==0:
            break


        elif terminated==False:
            while weightA + weightB + b > K:
                if len(candidateA)>0:
                    weightA -= candidateA.pop()
                    current_count -= 1
                else:
                    terminated=True

            if weightA + weightB + b <= K:
                weightB += b
                candidateB.append(b)
                current_count += 1
        max_count = max(max_count, current_count)

    print(max_count)
    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:
import sys

def resolve():
    lines = sys.stdin.readlines()

    n, m, k = tuple(map(int, lines[0].strip().split(' ')))
    a = list(map(int, lines[1].strip().split(' ')))
    b = list(map(int, lines[2].strip().split(' ')))
    c_max = 0
    c = 0
    s = 0
    for q in b:
        s += q
        if s > k:
            break
        c += 1
    c_max = max(c, c_max)
    for j in range(c, -1, -1):
        s -= b[j-1]
        if s > k:
            continue
        sa = s
        ca = j
        for p in a:
            sa += p
            if sa > k:
                break
            ca += 1
        c_max = max(ca, c_max)

    print(c_max)

resolve()

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 = K
ans = 0
a = 0
b = 0
while True:
    if a >= N:
        if b >= N:
            if B[b] == time:
                ans += 1
            break
        time -= B[b]
        b += 1
    elif b >= M:
        if a >= N:
            if A[a] == time:
                ans += 1
            break
        time -= A[a]
        a += 1
    else:
        if A[a] > K or B[b] > K:
            break
        if(A[a] < B[b]):
            time -= A[a]
            a += 1
        else:
            time -= B[b]
            b += 1
    if time <= 0:
        break
    ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
"""机AにNさつ"""

N, M, K = map(int, input().split())
arr_a = list(map(int, input().split()))[::-1]
arr_b = list(map(int, input().split()))[::-1]

count = 0
ans = 0

while True:
    if count >= K:
        if count == K:
            print(ans)
            exit()
        if count > K:
            print(ans-1)
            exit()
    if len(arr_a) != 0 and len(arr_b) != 0:
        if arr_a[-1] >= arr_b[-1]:
            count += arr_b.pop()
            ans += 1
            continue
        else:
            count += arr_a.pop()
            ans += 1
            continue

    if len(arr_a) != 0 and len(arr_b) == 0:
            count += arr_a.pop()
            ans += 1
            continue

    if len(arr_a) == 0 and len(arr_b) != 0:
            count += arr_b.pop()
            ans += 1
            continue

    if len(arr_a) == 0 and len(arr_b) == 0:
        if count <= K:
            print(ans)
            exit()

        if count > K:
            print(ans-1)
            exit()

Submission status: Wrong Answer

Solution code:
a,c,v=map(int,input().split())
arr1=list(map(int,input().strip().split()))[:a]
arr2=list(map(int,input().strip().split()))[:c]
arr3=arr1+arr2
arr3.sort()
sum=0
ct=0
for x in range(0,(a+c)):
  sum=sum+arr3[x]
  ct+=1
  if(sum>=v):
    break
if(sum>v):
  print(ct-1)
else:
  print(ct)

Submission status: Wrong Answer

Solution code:
from collections import deque
import copy
N, M, K = map(int, input().split())
A = deque(list(map(int, input().split())))
B = deque(list(map(int, input().split())))
counter = 0
ans = 0
a = A.popleft()
b = B.popleft()
while counter < K:
    ans += 1
    if a >= b:
        counter += b
        if not B:
            b = 0
            break
        b = B.popleft()
    else:
        counter += a
        if not A:
            a = 0
            break
        a = A.popleft()
if counter > K:
    print(ans - 1)
elif counter == K:
    print(ans)
else:
    if a == 0:
        A = B
        a = b
    while counter < K:
        ans += 1
        counter += a
        if not A:
            if counter < K:
                ans += 1
            break
        a = A.popleft()
    if counter == K:
        print(ans)
    else:
        print(ans - 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()))
t = 0
cnt = 0
for i in range(n + m):
    if a != [] and b != []:
        if a[0] <= b[0]:
            t += a[0]
            del a[0]
        else:
            t += b[0]
            del b[0]
    elif a == []:
        t += b[0]
        del b[0]
    else:
        t += a[0]
        del a[0]
    if t > k:
        break
    else:
        cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
max_c = 0
t = 0
cnt = 0
flag = 0

for i in range(n+1):
  for j in range(m+1):
    t = sum(a[:i]) + sum(b[:j])
    if t > k:
      print("ya")
      break
    else :
      if i+j > max_c:
        max_c = i+j
print(max_c)

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()))
mnt=0
i=1
mb=0
j=1
while mnt<=k and 0<i<n+1:
    mnt+=a[i-1]
    i+=1
if mnt>k:
    i-=2
    mnt-=a[i]
else:
    i-=1

while i>0:

    while mnt<=k and j<m+1:
        mnt+=b[j-1]
        j+=1
    if mnt>k:
        j-=2
        mnt-=b[j]
    else:
        j-=1
        
    if i+j>mb:
        mb=i+j
    
    mnt-=a[i-1]
    i-=1            
            
            
print(mb)

Submission status: Wrong Answer

Solution code:
N,M,K = [int(num) for num in input().split()]
A_list = [int(num) for num in input().split()]
B_list = [int(num) for num in input().split()]

read_min = K
read_cnt = 0
ai = 0
bi = 0

for _ in range(N+M):
  if ai < N and bi < M:
    if A_list[ai] < B_list[bi]:
      read_min -= A_list[ai]
      if read_min < 0:
        break
      ai += 1
    elif A_list[ai] >= B_list[bi]:
      read_min -= B_list[bi]
      if read_min < 0:
        break
      bi += 1
  else:
    if ai >= N:
      read_min -= B_list[bi]
      if read_min < 0:
        break
      bi += 1
    elif bi >= M:
      read_min -= A_list[ai]
      if read_min < 0:
        break
      ai += 1
    else:
      break
    
  read_cnt += 1  


print(read_cnt)

Submission status: Wrong Answer

Solution code:
import numpy as np
#from numba import njit

#(N, K) = map(int, input().split())
#A = np.array(list(map(int, input().split())))
(N,M,K) = map(int, input().split())
A = np.array(list(map(int, input().split())))
B = np.array(list(map(int, input().split())))

#@njit

for i in range(1,len(A)):
    A[i] += A[i-1]
for i in range(1,len(B)):
    B[i] += B[i-1]

c = 0
aa = 0
bb = 0
ia = 0
ib = 0
cont = True
while(cont):
    if len(A) <= ia:
        if len(B) <= ib :
            cont = False
        elif B[ib]+aa <= K:
            bb = B[ib]
            ib += 1
            c += 1
        else:
            cont = False
    else:
        if len(B) <= ib:
            if A[ia]+bb <= K:
                aa = A[ia]
                ia += 1
                c += 1
            else:
                cont = False
        else:
            if A[ia] < B[ib]:
                if A[ia]+bb <= K:
                    aa = A[ia]
                    ia += 1
                    c += 1
                else:
                    cont = False
            else:
                if B[ib]+aa <= K:
                    bb = B[ib]
                    ib += 1
                    c += 1
                else:
                    cont = False

print(c)

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

x = len(a) + len(b)
ax = a.pop(0)
bx = b.pop(0)
mx = 100000000
mins = []
for i in range(x):
    mins += [min(ax,bx)]
    if ax == mins[-1]:
        if len(a) > 0:
            ax = a.pop(0)
        else:
            ax = mx
    else:
        if len(b)>0:
            bx = b.pop(0)
        else:
            bx = mx
    if sum(mins) > k:
        mins.pop(-1)
        break
    if sum(mins) == k:
        break
print(len(mins))

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:
    try:
        if a_idx+1==N:
            time+=b[b_idx]
            b_idx+=1
            continue
        elif b_idx+1==M:
            time+=a[b_idx]
            a_idx+=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:
            try:
                a_com=a_idx
                b_com=b_idx
                while True:
                    if a[a_com]>b[b_com]:
                        time+=a[a_idx]
                        
                        a_idx+=1
                        
                        break
                    elif a[a_com]<b[b_com]:
                        time+=b[b_idx]
                        
                        b_idx+=1
                        
                        break
                    a_com+=1
                    b_com+=1
            except:
                time+=a[a_idx]
                a_idx+=1
        if time<K:
            count+=1
                
    except:
        break
print(count)

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(100000000000)
    B.append(100000000000)
    a, b = 0, 0
    answer = 0

    while True:
        if A[a] < B[b]:
            going_to_read = A[a]
            a += 1
        elif A[a] > B[b]:
            going_to_read = B[b]
            b += 1
        else:
            if A[a+1] < B[b+1]:
                going_to_read = A[a]
                a += 1
            else:
                going_to_read = B[b]
                b += 1

        if K >= going_to_read:
            answer += 1
            K -= going_to_read
        else: break

        if a == N and b == M: break

    print(answer)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np

n, m, k = [int(e) for e in input().split()]
a = np.array([int(e) for e in input().split()])
b = np.array([int(e) for e in input().split()])

asum = a.cumsum()
bsum = b.cumsum()

#aのみbのみ
onlya = (asum < k).sum()
onlyb = (bsum < k).sum()
ans = max(onlya,onlyb)

asum = asum[:onlya]
bsum = bsum[:onlyb]

for i,t in enumerate(asum):
    for j,s in enumerate(bsum):
        if t+s <= k and i+j+2 > ans:
            ans = i+j+2

print(ans)

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(K)
print(res)

Submission status: Wrong Answer

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

A_index = 0
B_index = 0
ans = 0
minute = 0
for i in range(N+M):
    if A[A_index] >= B[B_index]:
        minute += B[B_index]
        B_index+=1
        if A_index==N:
            A[A_index-1] = 10**10
        B_index=min(B_index, M-1)

        
    elif A[A_index] <= B[B_index]:
        minute += A[A_index]
        A_index+=1
        if B_index==M:
            B[B_index-1] = 10**10
        A_index=min(A_index, N-1)
    
    if minute > K:
        break
    ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
# n,m,k=3,4,240
# a=[60,90,120]
# b=[80,150,80,150]

def stacked(n,m,k,a,b):
    i=0
    j=0
    cnt=0
    f=0
    while(i<n and j<m and k>=0):
        if(a[i]<b[j]):
            if(k-a[i]>=0):
                k=k-a[i]
                cnt+=1
                i+=1
            else:
                f=1
                break
        else:
            if(k-b[j]>=0):
                k=k-b[j]
                cnt+=1
                j+=1
            else:
                f=1
                break
    while(i<n and k>=0):
        if(k-a[i]>=0):
            k=k-a[i]
            cnt+=1
            i+=1
        else:
            break
    while(j<m and k>=0):
        if(k-b[j]>=0):
            k=k-b[j]
            cnt+=1
            j+=1
        else:
            break
    print(cnt)   
stacked(n,m,k,a,b)

Submission status: Wrong Answer

Solution code:
from collections import deque

n, m, k = map(int, input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
time = 0
ans = 0
aaa = deque(a)
bbb = deque(b)
while (time < k):
    if ((len(aaa) > 0)  &  (len(bbb) > 0)):
        if aaa < bbb:
            time += aaa.popleft()
            ans += 1
        else:
            time += bbb.popleft()
            ans += 1            
    elif aaa:
        time += aaa.popleft()
        ans += 1
    elif bbb:
        time += bbb.popleft()
        ans += 1
    else:
        break
if time <= k:
    print(ans)
else:
    print(ans - 1)

Submission status: Wrong Answer

Solution code:
import bisect
n, m, k = map(int, input().split())
aList = list(map(int, input().split()))
bList = list(map(int, input().split()))

cList = [0]
dList = [0]
for a in aList:
    t = a + cList[-1]
    if t < k:
        cList.append(a + cList[-1])
for b in bList:
    t = b + dList[-1]
    if t < k:
        dList.append(b + dList[-1])
cList.pop(0)
dList.pop(0)
n = len(cList)
m = len(dList)

if len(cList) == 0:
    print(bisect.bisect_right(dList, k))
else:
    a = 0
    for i in range(0, n+1):
        lim = k - cList[n-1-i]
        a = max(a, n - i + bisect.bisect_right(dList, lim))
    print(a)

Submission status: Wrong Answer

Solution code:
def which(shelf, idx):
    i, j = idx
    if i == len(shelf[0]) and j == len(shelf[1]):
        return 2
    elif i == len(shelf[0]):
        return 1
    elif j == len(shelf[1]):
        return 0

    while shelf[0][i] == shelf[1][j]:
        if i + 1 != len(shelf[0]):
            i += 1
        if j + 1 != len(shelf[1]):
            j += 1

        if i + 1 == len(shelf[0]) and j + 1 == len(shelf[1]):
            return 0

    if shelf[0][i] > shelf[1][j]:
        return 1
    else:
        return 0


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

    idx = [0, 0]
    total = 0
    while k > 0:
        x = which(shelf, idx)

        k -= shelf[x][idx[x]]
        idx[x] += 1

        if k >= 0:
            total += 1
        else:
            break

    print(total)


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
ans_a = 0
ans_b = 0
for i in range(N):
    if time + A[i] > K:
        break
    else:
        time += A[i]
        ans_a += 1
for i in range(M):
    if time + B[i] > K:
        break
    else:
        time += B[i]
        ans_b += 1
tmp = ans_a+ans_b
tmp2 = ans_a+ans_b
cnt_b = ans_b
for i in range(ans_a):
    time -= A[ans_a-i-1]
    tmp2 -= 1
    while True:
        if cnt_b == M:
            break
        if time + B[cnt_b] > K:
            break
        else:
            time += B[cnt_b]
            cnt_b += 1
            tmp2 += 1
print(max(tmp,tmp2))

Submission status: Wrong Answer

Solution code:
from collections import deque

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

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

ans = 0

while K > 0:
    if len(A) != 0:
        if len(B) == 0:
            if A[0] > K:    # 所要時間を超えてしまう
                break
            K -= A.popleft()
            ans += 1
            continue
        if A[0] <= B[0]:
            if A[0] > K:    # 所要時間を超えてしまう
                break
            K -= A.popleft()
            ans += 1
            continue
    if len(B) != 0:
        if len(A) == 0:
            if B[0] > K:    # 所要時間を超えてしまう
                break
            K -= B.popleft()
            ans += 1
            continue
        if A[0] > B[0]:
            if B[0] > K:    # 所要時間を超えてしまう
                break
            K -= B.popleft()
            ans += 1
            continue

print(ans)

Submission status: Wrong Answer

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

from collections import deque

a = deque(a+[10**100])
b = deque(b+[10**100])

ans=0
time=0
while time<=k:
    if  a[0]<b[0]:
        time+=a[0]
        if time>k:
            break
        ans+=1
        a.popleft()
    elif a[0]>=b[0]:
        time+=b[0]
        if time>k:
            break
        ans+=1
        b.popleft()
    else:
        break
print(ans)

Submission status: Wrong Answer

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

ia = 0
ib = 0
t= 0
f = 0
length = len(A) + len(B)

for i in range(length):

    if len(A) and len(B) > 0:
        if A[0] > B[0]:
            t = t + B[0]
            f = f + 1
            B.remove(B[0])
            if t > K:
                f = f -1
                break
        else:
            t = t + A[0]
            f = f + 1
            A.remove(A[0])
            if t > K:
                f = f -1
                break

    elif len(A) == 0:
            t = t + B[0]
            f = f + 1
            B.remove(B[0])   
            if t > K:
                f = f -1
                break
    elif len(B) == 0:
            t = t + A[0]
            f = f + 1
            A.remove(A[0])
            if t > K:
                f = f -1
                break

print(f)

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()))
##print(A+B)
C = A+B
C.sort()
##print(C)
i = 0
goukei = 0
if K >= sum(C):
    print(N+M)
else:
    while goukei < K: 
        goukei += C[i]
        i += 1
    print(i-1)

Submission status: Wrong Answer

Solution code:
N,M,K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ctr = 0
T = 0
while T <= K:
  try:
    if A[0] > B[0]:
      k = B[0]
      B.remove(B[0])
    elif A[0] < B[0]:
      k = A[0]
      A.remove(A[0])
    else:
      k = A[0] + B[0]
      A.remove(A[0])
      B.remove(B[0])
  except IndexError:
      if A == [] and B != []:
          k = B[0]
          B.remove(B[0])
      elif B == [] and A != []:
          k = A[0]
          A.remove(A[0])
  T += k
  if T <= K:
    ctr += 1
print(ctr)

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)
b.append(10**10)

ai = 0
bi = 0
t = 0
c= 0
ab = []
while ai != n or bi != m:
    if a[ai] == b[bi]:
        if a[ai + 1] > b[bi + 1]:
            ab.append(b[bi])
            bi += 1
        else:
            ab.append(a[ai])
            ai += 1
    elif a[ai] > b[bi]:
        ab.append(b[bi])
        bi += 1
    else:
        ab.append(a[ai])
        ai += 1

for i in range(n + m):
    t += ab[i]
    if t > k:
        break
    else:
        c += 1

print(c)

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()))
# print("A:", A, "B:", B)
ans = 0


while K > 0:
    if len(A) == 0:
        if K >= B[0]:
            K -= B[0]
            ans += 1
            B.pop(0)
            # print("A:", A, "B:", B)
        else:
            break
    elif len(B) == 0:
        if K >= A[0]:
            K -= A[0]
            ans += 1
            A.pop(0)
            # print("A:", A, "B:", B)
        else:
            break
    elif A[0] > B[0]:
        if K >= B[0]:
            K -= B[0]
            ans += 1
            B.pop(0)
            # print("A:", A, "B:", B)
        else:
            break
    elif A[0] < B[0]:
        if K >= A[0]:
            K -= A[0]
            ans += 1
            A.pop(0)
            # print("A:", A, "B:", B)
        else:
            break
    else:
        if K >= B[0]:
            K -= B[0]
            ans += 1
            B.pop(0)
            # print("A:", A, "B:", B)
        else:
            break
print(ans)

Submission status: Wrong Answer

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

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

time = 0
ai, bi = 0, 0

while time <= K:
    if ai == N:
        if bi == M:
            break
        else:
            time += B[bi]
            bi += 1
    elif bi == M:
        time += A[ai]
        ai += 1
    elif A[ai] <= B[bi]:
        time += A[ai]
        ai += 1
    else:
        time += B[bi]
        bi += 1

cnt = ai + bi
if time > K:
    cnt -= 1

print(cnt)