Problem:


Score : 300 points

Problem Statement

We have two desks: A and B. Desk A has a vertical stack of N books on it, and Desk B similarly has M books on it.

It takes us A_i minutes to read the i-th book from the top on Desk A (1 \leq i \leq N), and B_i minutes to read the i-th book from the top on Desk B (1 \leq i \leq M).

Consider the following action:

Choose a desk with a book remaining, read the topmost book on that desk, and remove it from the desk.

How many books can we read at most by repeating this action so that it takes us at most K minutes in total? We ignore the time it takes to do anything other than reading.

Constraints

1 \leq N, M \leq 200000

1 \leq K \leq 10^9

1 \leq A_i, B_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M K
A_1 A_2 \ldots A_N
B_1 B_2 \ldots B_M

Output

Print an integer representing the maximum number of books that can be read.

Sample Input 1

3 4 240
60 90 120
80 150 80 150

Sample Output 1

3

In this case, it takes us 60, 90, 120 minutes to read the 1-st, 2-nd, 3-rd books from the top on Desk A, and 80, 150, 80, 150 minutes to read the 1-st, 2-nd, 3-rd, 4-th books from the top on Desk B, respectively.

We can read three books in 230 minutes, as shown below, and this is the maximum number of books we can read within 240 minutes.

Read the topmost book on Desk A in 60 minutes, and remove that book from the desk.

Read the topmost book on Desk B in 80 minutes, and remove that book from the desk.

Read the topmost book on Desk A in 90 minutes, and remove that book from the desk.

Sample Input 2

3 4 730
60 90 120
80 150 80 150

Sample Output 2

7

Sample Input 3

5 4 1
1000000000 1000000000 1000000000 1000000000 1000000000
1000000000 1000000000 1000000000 1000000000

Sample Output 3

0

Watch out for integer overflows.



Sample input:
3 4 240
60 90 120
80 150 80 150


Sample output:
3

Submission status: Wrong Answer

Solution code:
n,m,k=map(int, input().split())
A=list(map(int, input().split()))
B=list(map(int, input().split()))
A.append(10000000000000000)
B.append(10000000000000000)
a=0
b=0
cnt=0
for i in range(n+m):
	if a==n and k>=B[b]:
		k-=B[b]
		cnt+=1
		b+=1
	elif b==m and k>=A[a]:
		k-=A[a]
		cnt+=1
		a+=1	
	elif min(A[a],B[b])>k:
		break 
	elif A[a]>=B[b]:
		k-=B[b]
		b+=1
		cnt+=1
	else:
		k-=A[a]
		a+=1
		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()))
minute = 0
ans = 0
while minute <= k:
    if not a and not b:
        ans += 1
        break
    elif not a:
        minute += b.pop(0)
        ans += 1
    elif not b:
        minute += a.pop(0)
        ans += 1
    elif a <= b:
        minute += a.pop(0)
        ans += 1
    else:
        minute += b.pop(0)
        ans += 1
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()))


time = 0
i=0
k=0

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
    elif k>=M and i>=N:
        print(M+N)
        exit()
    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
    
        
    
print(i+k)

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:
    if a >= b:
        counter += b
        ans += 1
        if not B:
            b = 0
            break
        b = B.popleft()
    else:
        counter += a
        ans += 1
        if not A:
            a = 0
            break
        a = A.popleft()
if counter > K:
    print(ans - 1)
else:
    if a == 0:
        A = copy.deepcopy(B)
        a = b
    while counter < K:
        ans += 1
        counter += a
        if not A:
            ans += 1
            break
        a = A.popleft()
    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())) #分
i=0
j=0
y=0

while True:
    if (K - A[i] < 0) and (K - B[j] <0):
        break
    if A[i] <= B[j]:
        K -= A[i]
        y += 1
        i += 1
        
    if i > len(A)-1 or j > len(B)-1:
        break
    if (K - A[i] <= 0) and (K - B[j] <=0):
        break
        
    if B[j] < A[i]:
        K -= B[j]
        y += 1
        j += 1
        
    if i > len(A)-1 or j > len(B)-1:
        break
    if (K - A[i] <= 0) and (K - B[j] <=0):
        break
    
    
    

print(y)

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
t = 0
c = 0
while 1 == 1:
    if i >= n and j >= m:
        break 
    if i >= n:
        t = t + b[j]
        if t > k:
            break
        j = j + 1
        c = c + 1
    elif j >= m:
        t = t + a[i]
        if t > k:
            break
        i = i + 1
        c = c + 1

    elif a[i] < b[j]:
        t = t + a[i]
        if t > k:
            break
        i = i + 1
        c = c + 1
    else:
        t = t + b[j]
        if t > k:
            break
        j = j + 1
        c = 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()))
a += [1000000001] * 199999
b += [1000000001] * 199999
c = 0
ctm = 0
t = 0
for i in range(n + m):
    if a[0] >= b[0]:
        t = b.pop(0)
    else:
        t = a.pop(0)
    if ctm + t <= k:
        ctm += t
        c += 1
    else:
        break
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()))

flag = True
gokei = 0
count = 0
index_of_a = 0
index_of_b = 0


for i in range(n+m):
    if flag and a:
        gokei += a.pop(index_of_a)
        count += 1
        flag = False
    elif b:
        gokei += b.pop(index_of_b)
        count += 1
        flag = True
    
    if gokei > k:
        count -= 1
        break
print(count)

Submission status: Wrong Answer

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

count = 0
_sum = 0
acount = 0
bcount = 0
A_sum = [0]
B_sum = [0]
for a in A_list:
    A_sum.append(A_sum[-1] + a)
    if A_sum[-1] <= K:
        acount += 1
for b in B_list:
    B_sum.append(B_sum[-1] + b)
    if B_sum[-1] <= K:
        bcount += 1

if acount == bcount == 0:
    print(0)
    exit()
elif acount == bcount:
    count = acount if A_sum[acount - 1] < B_sum[bcount - 1]else bcount
    _sum = A_sum[acount - 1] if A_sum[acount - 1] < B_sum[bcount - 1]else B_sum[bcount - 1]
    if A_sum[acount - 1] < B_sum[bcount - 1]:
        for b in B_list:
            _sum += b
            if _sum > K:
                break
            count += 1
    else:
        for a in A_list:
            _sum += a
            if _sum > K:
                break
            count += 1

elif acount > bcount:
    count = acount
    _sum = A_sum[acount - 1]
    for b in B_list:
        _sum += b
        if _sum > K:
            break
        count += 1
else:
    count = bcount
    _sum = B_sum[bcount - 1]
    for a in A_list:
        _sum += a
        if _sum > K:
            break
        count += 1

print(count)

Submission status: Wrong Answer

Solution code:
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_list(N): return [s_list() for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def main():
    n, m, k = i_map()
    a_list = i_list()
    b_list = i_list()

    a_deque = deque(a_list)
    b_deque = deque(b_list)

    read_time = 0

    for i in range(n+m):
        if read_time > k:
            print(i-1)
            exit()
        # if read_time == k:
        #     print(i)
        #     exit()

        if len(a_deque) == 0:
            a = INF
        else:
            a = a_deque.popleft()
        if len(b_deque) == 0:
            b = INF
        else:
            b = b_deque.popleft()

        if a <= b:
            read_time += a
            b_deque.appendleft(b)
            # print(i,read_time)
        else:
            read_time += b
            a_deque.appendleft(a)
            # print(i,read_time)

    print(n+m)
 
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[0]<= 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[0]<= 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-1]
        if m == 0:
            if B[0] <= L:
                m = 1
        if m >= 1:
            while(m<M and B[m]<=L):
                m += 1
        if max + m > ans:
            ans = max+m
    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
N, M, K = map(int, input().split())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
if sum(A) + sum(B) <= K:
    print(len(A)+len(B))
else:
    A = deque(A)
    B = deque(B)
    time = 0
    ans = 0
    while time <= K:
        if len(A) == 0:
            time += B[0]
            ans += 1
            B.popleft()
        elif len(B) == 0:
            time += A[0]
            ans += 1
            A.popleft()
        else:
            if A[0] <= B[0]:
                time += A[0]
                ans += 1
                A.popleft()
            else:
                time += B[0]
                ans += 1
                B.popleft()
    print(ans-1)

Submission status: Wrong Answer

Solution code:
import numpy as np
from collections import deque
n, m, k = [int(k) for k in input().split()]
r = 0
c = 0
d = deque(np.sort(np.concatenate([np.array([int(k) for k in input().split()], dtype=int), np.array([int(k) for k in input().split()], dtype=int)]))[::-1])
while True:
    r += d.pop()
    if r <= k:
        c += 1
    else:
        break
    if len(d) == 0:
        break
print(c)

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

ans = 0
time = 0

while True:
    if len(a) == 0 and len(b) == 0:
        break
    if len(a) < 1:
        b_pop = b.popleft()
        time += b_pop
        ans += 1
        continue

    if len(b) < 1:
        a_pop = a.popleft()
        time += a_pop
        ans += 1
        continue

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

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

Submission status: Wrong Answer

Solution code:
from collections import deque

(n, m, k), aa, bb = [deque(map(int, l.split())) for l in open(0)]

ans = 0

while 1:
    nx = k

    if len(aa):
        nx = min(nx, aa[0])

    if len(bb):
        nx = min(nx, bb[0])

    if len(aa) and aa[0] == nx:
        k-=aa.popleft()
        ans += 1
        
    elif len(bb) and bb[0] == nx:
        k-=bb.popleft()
        ans += 1
        
    else:
        break

print(ans)

Submission status: Wrong Answer

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

a_num = 0
b_num = 0
ans = 0
time = 0
for i in range(nmk[0]+nmk[1]):
    try:
        if a[a_num]<b[b_num]:
            time += a[a_num]
            if time<=nmk[2]:
                ans += 1
                a_num += 1
            else:
                break
        else:
            time += b[b_num]
            if time<=nmk[2]:
                ans += 1
                b_num += 1
            else:
                break
    except:
        if a_num==nmk[0]:
            time += b[b_num]
            if time<=nmk[2]:
                ans += 1
                b_num += 1
            else:
                break
        elif b_num==nmk[1]:
            time += a[a_num]
            if time<=nmk[2]:
                ans += 1
                a_num += 1
            else:
                break

print(ans)

Submission status: Wrong Answer

Solution code:
N,M,K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
time = 0
cntA = 0
cntB = 0
while time < K:
    if cntA == len(A):
        tmp = B[cntB]
        if K < tmp + time:
            break
        else:
            cntB += 1
    elif cntB == len(B):
        tmp = A[cntA]
        if K < tmp + time:
            break
        else:
            cntA += 1
    else:
        if A[cntA] > B[cntB]:
            tmp = B[cntB]
            if K < tmp + time:
                break
            else:
                cntB += 1
        else:
            tmp = A[cntA]
            if K < tmp + time:
                break
            else:
                cntA += 1
    if K < tmp + time:
        break
    else:
        time += tmp
print(cntA + cntB)

Submission status: Wrong Answer

Solution code:
from collections import deque
n,m,k = [int(e) for e in input().split()]
As = deque([int(e) for e in input().split()])
Bs = deque([int(e) for e in input().split()])
result = 0
while True:
    if not As and not Bs:
        break
    if not As and Bs[0]>k:
        break
    if not Bs and As[0]>k:
        break
    if not As and Bs[0]<=k:
        k = k-Bs.popleft()
        result = result + 1
        continue
    if not Bs and As[0]<=k:
        k = k-As.popleft()
        result = result + 1
        continue
    if As[0] < Bs[0]:
        min_reduce = As.popleft()
    else:
        min_reduce = Bs.popleft()

    if min_reduce > k:
        break
    else:
        k = k-min_reduce
        result = result+1
print(result)

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

s=0
ac=0
bc=0

for i in range(n):
  s=s+a[i]
  ac=ac+1
  if s > k:
    s=s-a[i]
    ac=ac-1
    break
for i in range(m):
  s=s+b[i]
  bc=bc+1
  if s > k:
    s=s-b[i]
    bc=bc-1
    break

print(ac+bc)

Submission status: Wrong Answer

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

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

while k > 0:
    if len(a)==0:
        k-=b[0]
        if k >= 0:
            ans+=1
            del b[0]
    elif len(b)==0:
        k-=a[0]
        if k >= 0:
            ans+=1
            del a[0]
    elif a[0] < b[0]:
         k-=a[0]
         if k >= 0:
            ans+=1
            del a[0]
    else:
        k-=b[0]
        if k >= 0:
            ans+=1
            del b[0]
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

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

count = 0
time = 0

tmp_A = A.pop(0)
tmp_B = B.pop(0)

for i in range(N+M):
    if tmp_A <= tmp_B:
        time += tmp_A
        if A != []:
            tmp_A = A.pop(0)
        else:
            tmp_A = 1000000001
    else:
        time += tmp_B 
        if B != []:
            tmp_B = B.pop(0)
        else:
            tmp_B = 1000000001
    if time > K:
        break
    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()))

ans = 0
a_ind = 0
b_ind = 0
while k > 0:
    if n > a_ind and m > b_ind:
        if a[0] < b[0]:
            if k >= a[0]:
                k -= a[a_ind]
                a_ind += 1
                ans += 1
            else:
                break
        else:
            if k >= b[0]:
                k -= b[b_ind]
                b_ind += 1
                ans += 1
            else:
                break
    elif n > a_ind and m == b_ind:
        if k >= a[0]:
            k -= a[a_ind]
            a_ind += 1
            ans += 1
        else:
            break
    elif n == a_ind and m > b_ind:
        if k >= b[0]:
            k -= b[b_ind]
            b_ind += 1
            ans += 1
        else:
            break
    else:
        break

print(ans)

Submission status: Wrong Answer

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

A=[]
B=[]

for a in A_in:
    A.append(int(a))
    
for b in B_in:
    B.append(int(b))

time = 0
cnt = 0

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

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

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

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))
A_Read = 0
B_Read = 0
A_Finish = 0
B_Finish = 0
ans = 0
while K >= 0:
    if A_Finish == 1 and B_Finish == 1:
        break
    elif A_Finish == 1:
        K -= B_list[B_Read]
        # print(B_list[B_Read])
        B_Read += 1
        if B_Read == M:
            B_Finish = 1
    elif B_Finish == 1:
        K -= A_list[A_Read]
        # print(A_list[A_Read])
        A_Read += 1
        if A_Read == N:
            A_Finish = 1
    else:
        if A_list[A_Read] <= B_list[B_Read]:
            K -= A_list[A_Read]
            # print(A_list[A_Read])
            A_Read += 1
            if A_Read == N:
                A_Finish = 1
        else:
            K -= B_list[B_Read]
            # print(B_list[B_Read])
            B_Read += 1
            if B_Read == M:
                B_Finish = 1
    if K < 0:
        break
    elif K == 0:
        ans += 1
        break
    # print(K)
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import math
from collections import Counter

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

a, b = 0, 0
time = 0
cnt = 0

while True:
    if a >= N:
        while True:
            if b >= M:
                break
            else:
                time += B[b]

            if time <= K:
                cnt += 1
                b += 1
            else:
                break
        break

    if b >= M:
        while True:
            if a >= N:
                break
            else:
                time += A[a]

            if time <= K:
                cnt += 1
                a += 1
            else:
                break
        break

    if A[a] < B[b]:
        time += A[a]
        a += 1
    else:
        time += B[b]
        b += 1
    
    if time <= K:
        cnt += 1
    else:
        break

print(cnt)

Submission status: Wrong Answer

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

ans = 0
time = 0
while True:
    book = None
    # AにもBにも本がない
    if len(A) == 0 and len(B) == 0:
        break
    # AにもBにも本がある
    if len(A) > 0 and len(B) > 0:
        for i in range(min(len(A), len(B))):
            if A[i] == B[i]:
                continue
            elif A[i] > B[i]:
                book = B.pop(0)
                break
            elif A[i] < B[i]:
                book = A.pop(0)
                break
    elif len(B) == 0 and len(A) > 0:
        book = A.pop(0)
    elif len(A) == 0 and len(B) > 0:
        book = B.pop(0)

    if book is None:
        break
    if time + book <= K:
        time += book
        ans += 1
    else:
        break

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()))
A = deque(A)
B = list(map(int, input().split()))
B = deque(B)
count = 0
ans = 0


flag = ""
while (True):
    if A[0] < B[0]:
        if count + A[0] <= K:
            ans += 1
            count += A[0]
            A.popleft()
            if len(A) == 0:
                flag = "A"
                break
        else: break
    else :
        if count + B[0] <= K:
            ans += 1
            count += B[0]
            B.popleft()
            if len(B) == 0:
                flag = "B"
                break
        else: break

if flag == "A":
    while (True):
        if count + B[0] <= K:
                ans += 1
                count += B[0]
                B.popleft()
                if len(B) == 0:
                    break
        else:break
elif flag == "B":
    while (True):
        if count + A[0] <= K:
                ans += 1
                count += A[0]
                A.popleft()
                if len(A) == 0:
                    break
        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()))
from bisect import bisect_right
dpa = [0]
for a in A:
    dpa.append(dpa[-1]+a)
dpb = [0]
for b in B:
    dpb.append(dpb[-1]+b)
ans = 0
for i in range(1, N+1):
    t = dpa[i]
    if t > K:
        break
    j = bisect_right(dpb, K-t)
    ans = max(ans, i + j - 1)
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
N,M,K=map(int, sys.stdin.readline().split())
A=map(int, sys.stdin.readline().split())
B=map(int, sys.stdin.readline().split())

L=[]

ai=0
bi=0
while ai<N or bi<M:
    if ai==N:   #A列が最後の値に達していたら
        b=B[bi]
        L.append(b) #bを1列に加え
        bi+=1   #Bを1つ進める
    elif bi==M:   #B列が最後の値に達していたら
        a=A[ai]
        L.append(a) #aを1列に加え
        ai+=1   #Aを1つ進める
    else:       #どっちもまだ列の最後に達していなければ
        a=A[ai]
        b=B[bi]
        if a<b:
            L.append(a) #aを1列に加え
            ai+=1   #Aを1つ進める
        elif b<a:
            L.append(b) #bを1列に加え
            bi+=1   #Bを1つ進める
        elif a==b:  #同じだったら
            L.append(a) #aを1列に加え
            ai+=1   #Aを1つ進める
            L.append(b) #bを1列に加え
            bi+=1   #Bを1つ進める

total=0
for i,x in enumerate(L):
    total+=x
    if K<total:
        print i
        quit()
else:
    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()))
aidx = 0
bidx = 0
ans = 0
time = 0
while True:
    if aidx < n and bidx < m:
        if a[aidx] < b[bidx]:
            time += a[aidx]
            if time > k:
                break
            aidx += 1
            ans += 1
        else:
            time += b[bidx]
            if time > k:
                break
            bidx += 1
            ans += 1
    elif aidx < n:
        time += a[aidx]
        if time > k:
            break
        ans += 1
        aidx += 1
    elif bidx < m:
        time += b[bidx]
        if time > k:
            break
        ans += 1
        bidx += 1
    else:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
#import string
#from collections import defaultdict, deque, Counter
#import bisect
#import heapq
#import math
#from itertools import accumulate
#from itertools import permutations as perm
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as combr
#from fractions import gcd
#import numpy as np

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

def solve():
    n,m,k = map(int, stdin.readline().rstrip().split())
    A = list(map(int, stdin.readline().rstrip().split()))
    B = list(map(int, stdin.readline().rstrip().split()))
    #numbers = [[int(c) for c in l.strip().split()] for l in sys.stdin]
    #word = [stdin.readline().rstrip() for _ in range(n)]
    #number = [[int(c) for c in stdin.readline().rstrip()] for _ in range(n)]
    #zeros = [[0] * w for i in range(h)]
    ans = 0
    a = 0
    b = 0
    time = 0
    while a<len(A) and b<len(B):
        if A[a] < B[b]:
            if time + A[a] > k:
                print(ans)
                exit()
            else:
                ans += 1
                time += A[a]
                a += 1
        else:
            if time + B[b] > k:
                print(ans)
                exit()
            else:
                ans += 1
                time += B[b]
                b += 1
    if a==n:
        while b<len(B):
            if time + B[b] > k:
                print(ans)
                exit()
            else:
                ans += 1
                time += B[b]
                b += 1
    else:
        while a<len(A):
            if time + A[a] > k:
                print(ans)
                exit()
            else:
                ans += 1
                time += A[a]
                a += 1
    print(ans)




if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

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

ans = 0

while K>0 or len(A)!=0 or len(B)!=0:
    if len(B)==0:
        K -= A[0]
        A.pop(0)
        ans += 1
    elif len(A)==0:
        K -= B[0]
        B.pop(0)
        ans += 1
    elif A[0] <= B[0]:
        K -= A[0]
        A.pop(0)
        ans += 1
    elif A[0] > B[0]:
        K -= B[0]
        B.pop(0)
        ans += 1

if K < 0:
    ans -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
a,b,c = map(int,input().split())
z = list(map(int,input().split()))
x = list(map(int,input().split()))
if c>=sum(z)+ sum(x):
	print(a+b)
else:
	i,j,q,r=0,0,0,0
	while c>0 and i+j<=(a+b):
		if i<=(a-1) and j<=(b-1):
			if z[i]<=x[j]:
				c-=z[i]
				i+=1
			else:
				c-=x[j]
				j+=1
		else:
			if j==b:
				c-=z[i]
				i+=1
			if i==a:
				c-=x[j]
				j+=1
		r+=1
	print(r-1)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力

def popup(a, b):
    if len(a) == 0 and len(b) != 0:
        return b.pop()
    if len(a) != 0 and len(b) == 0:
        return a.pop()

    if a[0] <= b[0]:
        return a.pop(0)
    else:
        return b.pop(0)


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

    cost = 0
    count = 0

    if a_lst[0] > k and b_lst[0] > k:
        print(0)
        exit(0)

    while True:
        if len(a_lst) == 0 and len(b_lst) == 0:
            break

        tmp = popup(a_lst, b_lst)
        cost = cost + tmp
        count = count + 1
        if cost > k:
            cost = cost - tmp
            count = count - 1
            break
        

    print(count)



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

answer = 0
time = 0

while True:
    if len(a) == 0 and len(b) == 0:
        break
    if len(a) == 0:
        time += b[0]
        b.pop(0)
    elif len(b) == 0:
        time += a[0]
        a.pop(0)
    else:
        if a[0] > b[0]:
            time += b[0]
            b.pop(0)
        elif a[0] <= b[0]:
            time += a[0]
            a.pop(0)
    
    if time <= K:
        answer += 1
    else:
        break

print(answer)

Submission status: Wrong Answer

Solution code:
# coding: utf-8

import sys
import math
import collections
import itertools
import bisect
INF = 10 ** 13
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return x if y == 0 else gcd(y, x%y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def LS() : return input().split()
def RS(N) : return [input() for _ in range(N)]
def LRS(N) : return [input().split() for _ in range(N)]
def PL(L) : print(*L, sep="\n")
def YesNo(B) : print("Yes" if B else "No")
def YESNO(B) : print("YES" if B else "NO")

N, M, K = LI()
A = LI()
B = LI()
A.append(INF)
B.append(INF)

now = 0
a = 0
b = 0
ans = 0
while True:
    m = min(A[a], B[b])

    if now + m <= K:
        now += m
        ans += 1

        if m == A[a]:
            a += 1
        else:
            b += 1
        if a >= N:
            a = N-1
        if b >= M:
            b = M-1        
    else:
        break

print(ans)