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:
def resolve():
    n, m, k = map(int, input().split())
    A = list(map(int, input().split())) 
    B = list(map(int, input().split()))
    
    ans = 0
    total = 0
    i = 0
    j = 0
    for _ in range(max(n, m)):
        if i < n:
            a = A[i]
        else:
            a = 10**9 + 1
        if j < m:
            b = B[j]
        else:
            b = 10**9 + 1
        total += min(a, b)
        if min(a, b) == a:
            i += 1
        else:
            j += 1
        if total > k:
            break
        else:
            ans += 1
    print(ans)
resolve()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
N, M, K = [int(s) for s in input().split()]
A = [int(s) for s in input().split()]
B = [int(s) for s in input().split()]
i = 0
j = M-1

B_SUM = [0] * M
B_SUM[0] = B[0]

max_book = 0
if B_SUM[0] <= K:
    max_book = 1

for i in range(1, M):
    B_SUM[i] = B[i] + B_SUM[i - 1]
    if B_SUM[i] <= K:
        max_book = i + 1

A_SUM = 0

b_index = M - 1

for i in range(N):
    A_SUM += A[i]
    while (b_index >= 0):
        B_SUM[b_index]
        if A_SUM + B_SUM[b_index] <= K:
            max_book = max(max_book, b_index + 1 + i + 1)
            break
        b_index -= 1
    max_book = max(max_book, b_index + 1 + i + 1)

print(max_book)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import sys

l = stdin.readline().rstrip().split(' ')
a = stdin.readline().rstrip().split(' ')
b = stdin.readline().rstrip().split(' ')
k = int(l[2])
n = int(l[0])
m = int(l[1])
ia = 0
ib = 0
b_sum = 0
count = 0
a_sum = 0
res = []

for bt in b:
    b_sum += int(bt)
    if b_sum <= k:
        count += 1
    else:
        break
res.append(count)
count = 0
for at in a:
    a_sum = a_sum + int(at)
    if k <= a_sum:
        #res.append(count)
        print(max(res))
        sys.exit()
    else:
        count = ia + 1
    b_sum = a_sum
    for bt in b:
        b_sum += int(bt)
        if b_sum <= k:
            count += 1
        else:
            break
    ia += 1
    res.append(count)
print(max(res))

Submission status: Wrong Answer

Solution code:
N, M, K = input().split(' ')
n = int(N)
m = int(M)
k = int(K)

a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
total = 0
x = 0
y = 0

while k > 0:
    if n>x and m >y:
        k -= min(a[x],b[y])
        total +=1
        if min(a[x],b[y])==a[x]:
            x += 1
        else:
            y += 1
        continue
    elif n<=x and m > y:
        k -= b[y]
        total += 1
        y += 1
        continue
    elif m <= y and n > x:
        k -= a[x]
        total += 1
        x += 1
        continue
        
    else:
        break
        
if k <0:
    print(total - 1)
    
else:
    print(total)

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

a_wa = []
max_a_idx = None
for idx, a in enumerate(A):
    if idx == 0:
        a_wa.append(a)
    else:
        a_wa.append(a_wa[idx-1] + a)

    if a_wa[idx] > K:
        break

    max_a_idx = idx

b_wa = []
max_b_idx = None
for idx, b in enumerate(B):
    if idx == 0:
        b_wa.append(b)
    else:
        b_wa.append(b_wa[idx-1] + b)

    if b_wa[idx] > K:
        break

    max_b_idx = idx

if max_a_idx is None and max_b_idx is None:
    print(0)
    exit()
elif max_a_idx is None:
    print(max_b_idx + 1)
    exit()
elif max_b_idx is None:
    print(max_a_idx + 1)
    exit()

temp_a_idx = max_a_idx
temp_b_idx = 0
out_num_list = []
for idx in range(max_b_idx+1):
    while True:
        if temp_a_idx < 0:
            print(max_b_idx+1)
            exit()
        temp = a_wa[temp_a_idx] + B[idx]
        if temp <= K:
            temp_b_idx = idx
            break
        else:
            temp_a_idx -= 1
print(temp_a_idx + temp_b_idx + 2)

Submission status: Wrong Answer

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



a=0
b=0
time=0
ans=0
for i in range(n+m):
    if a==n and b==m:
        break
    elif a==n:
        now=B[b]
        b+=1
    elif b==m:
        now=A[a]
        a+=1
    else:
        if A[a]<=B[b]:
            now=A[a]
            a+=1
        else:
            now=B[b]
            b+=1
    
    if time+now>k:
        break
    else:
        time+=now
        ans+=1

print(ans)

Submission status: Wrong Answer

Solution code:
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
a = 0
b = 0
t_sum = 0
cnt = 0
flag = True

for _ in range(N+M):
  if A[a] <= B[b]:
    t_sum += A[a]
    cnt += 1
    a += 1
  else:
    t_sum += B[b]
    cnt += 1
    b += 1
  if t_sum > K:
    cnt -= 1
    break
  if a == N:
    for _ in range(M+1):
      if b == M:
        flag = False
        break
      t_sum += B[b]
      cnt += 1
      b += 1
      if t_sum > K:
        cnt -= 1
        flag = False
        break
  if not flag:
    break
  if b == M:
    for _ in range(N+1):
      if a == N:
        flag = False
        break
      t_sum += A[a]
      cnt += 1
      a += 1
      if t_sum > K:
        cnt -= 1
        flag = False
        break
  if not flag:
    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()))
c = 0
a = a[::-1]
b = b[::-1]
a_i = n-1
b_i = m-1
while min(a[max(a_i, 0)], b[max(b_i, 0)]) <= k:
    if a_i < 0 and b_i >= 0:
        if b[b_i] <= k:
            c += 1
            k -= b[b_i]
            b_i -= 1
    elif b_i < 0 and a_i >= 0:
        if a[a_i] <= k:
            c += 1
            k -= a[a_i]
            a_i -= 1
    elif a_i < 0 and b_i < 0:
        break
    elif a[a_i] < b[b_i]:
        c += 1
        k -= a[a_i]
        a_i -= 1
    elif a[a_i] > b[b_i]:
        c += 1
        k -= b[b_i]
        b_i -= 1
    elif a[a_i] == b[b_i]:
        if a[max(0, a_i-1)] <= b[max(0, b_i-1)]:
            c += 1
            k -= a[a_i]
            a_i -= 1
        elif a[max(0, a_i-1)] > b[max(0, b_i-1)]:
            c += 1
            k -= b[b_i]
            b_i -= 1

print(c)

Submission status: Wrong Answer

Solution code:
def aaa():
    n,m,k = map(int,input().split())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    if n >= m:
        for _ in range(m-n):
            a.append(10**9+1)
    else:
        for _ in range(n-m):
            b.append(10**9+1)
    c = []
    for i,j in zip(a,b):
        if i <= j:
            c.append(i)
            c.append(j)
        else:
            c.append(j)
            c.append(i)
    d = 0
    e = 0
    for i in c:
        if i+e < k:
            e += i
            d += 1
        else:
            return d
    return n + m
aaa()

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 = []
a.append(300000)
b.append(300000)
e = 0
f = 0
for i in range(len(a)):
    b.append(a[i])
while sum(c) < k:
    if a[e] <= b[f]:
        c.append(a[e])
        e += 1
    elif b[f] < a[e]:
        c.append(b[f])
        f += 1
    else:
        break
print(c)
if sum(c) == k:
    print(len(c))
else:
    print(len(c)-1)

Submission status: Wrong Answer

Solution code:
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n,m,k=nii()
a=lnii()
b=lnii()

nl=[]
for i in range(min(n,m)):
  aa=a[i]
  bb=b[i]
  if aa<=bb:
    nl+=[aa,bb]
  else:
    nl+=[bb,aa]

if n>m:
  nl+=a[m:]
elif n<m:
  nl+=b[n:]

#print(nl)

t=0
ans=0
for i in nl:
  t+=i
  if t>k:
    break
  else:
    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()))
s=0
pa,pb=[0,a[0]],[0,b[0]]
for i in range(1,n):
    pa.append(pa[-1]+a[i])
for i in range(1,m):
    pb.append(pb[-1]+b[i])
ac,bc=0,0
x,y=0,0
while ac<=n and pa[ac]<=k:
    ac+=1
    x=1

if x: ac-=1

while bc<=m and  pa[ac]+pb[bc]<=k:
    bc+=1
    y=1
if y: bc-=1
ans=ac+bc

for i in range(ac-1,-1,-1):
    for j in range(bc+1,m+1):
        if pa[ac]+pb[bc]>k: break
        ans=max(ans,ac+bc)
print(ans)

Submission status: Wrong Answer

Solution code:
import queue

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

Aq = queue.Queue()
Bq = queue.Queue()
for i in A:
    Aq.put(i)
for i in B:
    Bq.put(i)

total = 0
cnt = 0

while total <= K:
    if Aq.empty() and Bq.empty():
        cnt += 1
        break
    elif Aq.empty():
        total += Bq.get()
    elif Bq.empty():
        total += Aq.get()
    elif A[0] > B[0]:
        total += Aq.get()
    else:
        total += Bq.get()
    cnt += 1

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

total = []
i = 0
j = 0
while len(total) != len(a)+len(b):
  if i<len(a) and j<len(b):
    if a[i]>=b[j]:
      total.append(b[j])
      j+=1
    elif b[j]>=a[i]:
      total.append(a[i])
      i+=1
  elif i>=len(a):
    total.append(b[j])
    j+=1
  elif j>=len(b):
    total.append(a[i])
    i+=1

c = 0
while k>=0:
  k = k-total[c]
  c+=1
  if c == len(total):
    #print(c)
    break
if c == len(total):
  print(c)
else:
  print(c-1)

Submission status: Wrong Answer

Solution code:
n, m ,k = map(int,input().split())
a_list = [int(a) for a in input().split()][:n]
b_list = [int(b) for b in input().split()][:m]
time = 0
a_num = 0
b_num = 0
count = 0
print(a_list)
print(b_list)

while True:
    
    if (len(a_list) < a_num + 1) and (len(b_list) < b_num + 1): 
        break

    elif  (len(a_list) < a_num + 1) and (len(b_list) >= b_num + 1):
        time += b_list[b_num]      
        b_num += 1
     
    elif (len(a_list) >= a_num + 1) and (len(b_list) < b_num + 1):
        time += a_list[a_num]      
        a_num += 1
        
    elif (len(a_list) >= a_num + 1) and (len(b_list) >= b_num + 1):
        if a_list[a_num] < b_list[b_num]:
            time += a_list[a_num]
            a_num += 1
        else:
            time += b_list[b_num]      
            b_num += 1
    
    if time <= k:
        count += 1
    else:
        break

print(count)

Submission status: Wrong Answer

Solution code:
from statistics import mean
N,M,K=map(int, input().split())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
k=0
c=0
while k <= K:
    if len(a) > 0 and len(b)>0:
        if mean(a[:2]) < mean(b[:2]) and ((k+a[0]) <=K):
            k+=a[0]
            c+=1
            a.pop(0)
        elif mean(a[:2]) > mean(b[:2]) and ((k+b[0]) <=K):
            k+=b[0]
            c+=1
            b.pop(0)
        else:
            if (a[0] < b[0]) and ((k+a[0]) <=K):
                k+=a[0]
                c+=1
                a.pop(0)

            elif (a[0] > b[0]) and ((k+b[0]) <=K):
                k+=b[0]
                c+=1
                b.pop(0)
            else:
                break
    elif (len(a) > 0) and (len(b) ==0):
        if ((k+a[0]) <=K):
            k+=a[0]
            c+=1
            a.pop(0)
        else:
            break
    elif (len(b) > 0) and (len(a) ==0):
        if ((k+b[0]) <=K):
            k+=b[0]
            c+=1
            b.pop(0)
        else:
            break
    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()))
ai=[]
bi=[]
aa=0
bb=0
bmax=0
for x in range(n):
    aa+=a[x]
    if aa<=k:
        ai.append(aa)
        bmax=x+1
for x in range(m):
    bb+=b[x]
    if bb<=k:
        bi.append(bb)
    else:
        if x>bmax:
            bmax=x    
        break
for x in range(len(ai)-1,0,-1):
    mi=ai[x]
    countb=0
    mimi=mi
    while(mimi<=k and countb<=len(bi)-1):
        mimi=mi+bi[countb]
        if mimi<=k and (x+1+countb+1)>bmax:
            bmax=(x+1+countb+1)
        countb+=1
print(bmax)

Submission status: Wrong Answer

Solution code:
import sys
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(rs())
def rs_(): return [_ for _ in rs().split()]
def ri_(): return [int(_) for _ in rs().split()]

N, M, K = ri_()
A = ri_()
B = ri_()
a = 0
b = 0
arr_a = [0] * N
arr_b = [0] * M
ans = 0
f = 0
while True:
    if ans == N + M:
        break
    if f == 1:
        K -= A[a]
        if a < N - 1:
            a += 1
        else:
            f = 2
        if K >= 0:
            ans += 1
        else:
            break
    if f == 2:
        K -= B[b]
        if b < M - 1:
            b += 1
        else:
            f = 1
        if K >= 0:
            ans += 1
        else:
            break
    if A[a] < B[b]:
        K -= A[a]
        if a < N - 1:
            a += 1
        else:
            f = 2
        if K >= 0:
            ans += 1
        else:
            break
    elif A[a] > B[b]:
        K -= B[b]
        if b < M - 1:
            b += 1
        else:
            f = 1
        if K >= 0:
            ans += 1
        else:
            break
    else:
        if arr_a[a] == 1:
            K -= A[a]
            a += 1
            if K >= 0:
                ans += 1
            else:
                break
        elif arr_b[b] == 1:
            K -= B[b]
            b += 1
            if K >= 0:
                ans += 1
            else:
                break
        else:
            t = 0
            while True:
                if A[a + t] < B[b + t]:
                    for i in range(t):
                        arr_a[i] = 1
                    break
                elif A[a + t] > B[b + t]:
                    for i in range(t):
                        arr_b[i] = 1
                    break
                if a + t < N - 1 and b + t < M - 1:
                    t += 1
                if a + t == N - 1:
                    for i in range(t):
                        arr_b[i] = 1
                    break
                if b + t == M - 1:
                    for i in range(t):
                        arr_a[i] = 1
                    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 itertools import accumulate
aa=list(accumulate(a))
bb=list(accumulate(b))

from bisect import bisect_left,bisect

kmax=0
for i in range(n):
    if k<aa[i]:
        break
    kk=k-aa[i]
    k2=min(bisect(bb,kk),m-1)
#    k2=bisect(bb,kk)
    if k2<m-1 and bb[k2+1]==kk:
        k2+=1
#    print(i,k2)
    kmax=max(kmax,k2+i+1)

print(kmax)

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()))
a=[0]*N
b=[0]*M
a[0]=A[0]
b[0]=B[0]
for i in range(N-1):
    a[i+1]=a[i]+A[i]
for i in range(M-1):
    b[i+1]=b[i]+B[i]
diff=2*10**9
count=0
for i in range(N):
    j=bisect.bisect_left(b,K-a[i])-1
    if 0<=K-(a[i]+b[j])<=diff:
        diff=K-(a[i]+b[j])
        count=max(count,(i+1)+(j+1))
print(count)

Submission status: Wrong Answer

Solution code:


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

A = [i for i in map(int, input().split())]
B = [i for i in map(int, input().split())]
ans = 0
a = 0
b = 0
t = 0

while b != M or a != N:
    if b == M:
        if A[a]+t <= K:
            t += A[a]
            ans += 1
            a += 1
        else:
            break

    elif a == N:
        if B[b]+t <= K:
            t += B[b]
            ans += 1
            b += 1
        else:
            break
    elif B[b] >= A[a] and A[a]+t <= K:
        t += A[a]
        ans += 1
        a += 1
    elif B[b] < A[a]:
        t += A[a]
        ans += 1
        a += 1
    else:
        break


print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

a_sum = a.cumsum()
b_sum = b.cumsum()

ans = 0
for i,book in enumerate(a_sum):
  if book <= k:
    tmp = (b_sum <= k-book).sum()
    if tmp+i+1 > ans:
      ans = tmp+i+1

    b_sum = b_sum[:tmp]


print(ans)

Submission status: Wrong Answer

Solution code:
# 別変数の整数複数個
M, M, K = [int(x) for x in input().strip().split(" ")]
A = [int(x) for x in input().strip().split(" ")]
B = [int(x) for x in input().strip().split(" ")]

# def pick(A, B):
#     # print(A, B)
#     if len(A) == 0 and len(B) > 0:
#         return False
#     if len(B) == 0 and len(A) > 0:
#         return True
#     if A[0] < B[0]:
#         return True
#     elif A[0] > B[0]:
#         return False
#     return pick(A[1:], B[1:])

total = 0
cur = 0
while len(A) + len(B) > 0:
    if len(A) == 0:
        total += B.pop(0)
    elif len(B):
        total += A.pop(0)
    elif A[0] >= B[0]:
        total += A.pop(0)
    else:
        total += B.pop(0)
    if total > K:
        break
    cur += 1
    if len(A) + len(B) == 0:
        break
print(cur)

Submission status: Wrong Answer

Solution code:
import bisect
import itertools
n ,m ,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
a = list(itertools.accumulate(a))
b = list(itertools.accumulate(b))
A =bisect.bisect_left(a,k)
count=0

if A<n:
  if a[A]==k:
    A+=1
if b[0]>k:
  print(A)
  exit()
if a[0]>k:
  B =bisect.bisect_left(b,k)
  if B<m:
    if b[B]==k:
      B+=1
  print(B)
  exit()

for i in range(A,0,-1):
  ans=k-a[i-1]
  B =bisect.bisect_left(b,ans)
  if B<m:
    if b[B]==ans:
      B+=1
  count=max(count,i+B)
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 = A + [10 ** 10]
B = B + [10 ** 10]

time = 0
count = -1
while time <= K:
    if A[0] <= B[0]:
        time += A.pop(0)
    else:
        time += B.pop(0)
    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(" ")))


time=0

A.reverse()
B.reverse()

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

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

  else:
    if A[-1] < B[-1]:
      if time+A[-1] <= K:
        time+=A.pop()
      else:
        break
    else:
      if time+B[-1] <= K:
        time+=B.pop()
      else:
        break

print(N+M-len(A)-len(B))

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(10**9+1)
B.append(10**9+1)

Aflg=0
Bflg=0
jikan=0
count=0


while True:
    #print(Aflg,Bflg,jikan,count)
    if jikan>K:
        break
    else:
        if A[Aflg] <= B[Bflg]:
            jikan+=A[Aflg]
            Aflg+=1
            if Aflg>=N:
                Aflg=N
        else:
            jikan+=B[Bflg]
            Bflg+=1
            if Bflg>=N:
                Bflg=N
        count+=1

print(count-1)

Submission status: Wrong Answer

Solution code:
gen_input = list(map(int, input().split()))
time_a = list(map(int, input().split()))
time_b = list(map(int, input().split()))

length_a = gen_input[0]
length_b = gen_input[1]
time_const = gen_input[2]

if sum(time_a) + sum(time_b) == time_const:
    print(length_a + length_b)
elif time_const < min(time_a[0], time_b[0]):
    print(0)
elif time_const == min(time_a[0], time_b[0]):
    print(1)

else:
    num_read_books = 0
    i = 0
    j = 0
    while True:
        if (i < length_a) & (j < length_b):
            if time_a[i] >= time_b[j]:
                time_const -= time_b[j]
                j += 1
            else:
                time_const -= time_a[i]
                i += 1
            if time_const > 0:
                num_read_books += 1
            else:
                break
        
        elif (i == length_a) & (j < length_b):
            time_const -= time_b[j]
            j += 1
            if time_const > 0:
                num_read_books += 1
            else:
                break

        elif (i < length_a) & (j == length_b):
            time_const -= time_a[i]
            i += 1
            if time_const > 0:
                num_read_books += 1
            else:
                break
        else:
            break
    print(num_read_books)

Submission status: Wrong Answer

Solution code:
N, M, X = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A.append(10000000000)
B.append(10000000000)
A.reverse()
B.reverse()

pre_ans = 0
ans = 0
c = 0
temp = 0
while True:
  if pre_ans == ans:
    temp = 100000000000
  else:
    temp = 0
  if sum(A[-2:]) >= sum(B[-2:])+temp:
    if ans+B[-1] > X:
      pre_ans = ans
      if temp == 100000000000:
        break
      continue
    ans += B.pop()
    c += 1
    if len(B) == 1:
      B[0] *=10
  else:
    if ans+A[-1] > X:
      pre_ans = ans
      if temp == 100000000000:
        break
      continue
    ans += A.pop()
    c += 1
    if len(A) == 1:
      A[0] *=10
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()))
if sum(A)+sum(B)<=K:
    print(len(A)+len(B))
else:
    ans=0
    count=0
    while count<K and len(A)!=0 and len(B)!=0:
        m=min(A[0],B[0])
        count+=m
        if m==A[0]:
            A.popleft()
        else:
            B.popleft()
        ans+=1
    if count<K and len(A)==0:
        while count<K:
            m=B[0]
            count+=m
            B.popleft()
            ans+=1
    if count<K and len(B)==0:
        while count<K:
            m=A[0]
            count+=m
            A.popleft()
            ans+=1
    if count>K:
        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()))
ans = 0
num_a = n-1
num_b = 0
flg = True

total_time = sum(a)

for i in range(n):
    if total_time > k:
        total_time -= a[num_a]
        num_a -= 1
    else:
        for j in range(num_b, m):
            if total_time + b[num_b] > k:
                flg = False
                break
            else:
                total_time += b[num_b]
                num_b += 1
                flg = True


ans = num_a+1 + num_b+1
if flg is False:
    ans -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
N ,M ,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
result = 0
A.append(10**15)
B.append(10**15)

i,j = 0,0
for k in range(N+M):
    if A[i] <= B[j]:
        K -= A[i]
        i += 1
    else:
        K -= B[j]
        j += 1
    if K < 0:
        break
    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()))
 
ans_list = []
ans_list.append(0)

sum_a = 0
for i in range(len(a)):
  sum_a += a[i]
  sum_b = 0
  if sum_a > k:
    break
  if sum_a == k:
    temp = i+1
    ans_list.append(temp)
    break
  for j in range(len(b)):
    sum_b += b[j]
    if max(ans_list) < i+1+j:
      pass
    else:
      if (sum_a + sum_b) > k:
        temp = i+1+j
        ans_list.append(temp)
        break
      if (sum_a + sum_b) == k:
        temp = i+1+j+1
        ans_list.append(temp)
        break
      
sum_b = 0
for i in range(len(b)):
  sum_b += b[i]
  sum_a = 0
  if sum_b > k:
    break
  if sum_b == k:
    temp = i+1
    ans_list.append(temp)
    break
  for j in range(len(a)):
    sum_a += a[j]    
    if max(ans_list) < i+1+j:
      pass
    else:
      if (sum_b + sum_a) > k:
        temp = i+1+j
        ans_list.append(temp)
        break
      if (sum_b + sum_a) == k:
        temp = i+1+j+1
        ans_list.append(temp)
        break
      
print(max(ans_list))

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 += [10**11]
B += [10**11]

ans = 0
T = 0
a, b = 0, 0
while ans <= (N+M):
    if A[a] <= B[b]:
        T += A[a]
        a += 1
    else:
        T += B[b]
        b += 1
    if T > 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()))
ans=0
i=0
j=0
while (k>=0 and i <n and j<m):
    if a[i]<b[j]:
        k-=a[i]
        i+=1
    else:
        k-=b[j]
        j+=1
    if k>=0:
        ans+=1
while(k>=0 and i<n):
    k-=a[i]
    i+=1
    if k>=0:
        ans+=1
while(k>=0 and j<m):
    k-=b[j]
    j+=1
    if k>=0:
        ans+=1
 
print(ans)

Submission status: Wrong Answer

Solution code:
N,M,K = map(int, input().split())
A = list( map(int, input().split()) ) 
B = list( map(int, input().split()) ) 
C = []
while sum(C) <= K:
    try:
        if A[0] < B[0]:
            C.append(A[0])
            del A[0]
        else:
            C.append(B[0])
            del B[0]
    except IndexError:
        if len(A) != 0:
            C.append(A[0])
            del A[0]
        elif len(B) != 0:
            C.append(B[0])
            del B[0]
        else:
            break
if sum(C) > K:
    print(len(C)-1)
else:
    print(len(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()))


ans = 0
c = 0

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

Submission status: Wrong Answer

Solution code:
a = input().split(" ")
N = int(a[0])
M = int(a[1])
K = int(a[2])
Ai = input().split(" ")
Bi = input().split(" ")
Ai = [int(s) for s in Ai]
Bi = [int(s) for s in Bi]
time_ = int(K)
time0 = 0
acount = 0
bcount = 0

for i in range(10000000000000000):
    try:
        time0 += Ai[i]
        if time0 > time_:
            time0 -= Ai[i]
            break
        acount += 1
    except IndexError:
        break
atime = time0
time0 = 0
for i in range(10000000000000000):
    try:
        time0 += Bi[i]
        if time0 > time_:
            time0 -= Bi[i]
            break
        bcount += 1
    except IndexError:
        break
btime = time0
allc = bcount
if bcount > acount:
    hic = bcount
else:
    hic = acount
# AiからBiに移す
cip = 0
for i in range(acount):
    ci = i + cip
    cip = 0
    try:
        while time0 + Ai[ci] <= time_:
            time0 += Ai[ci]
            print(time0)
            allc += 1
            ci += 1
            cip += 1
            if hic < allc:
                hic = allc
    except IndexError:
        pass
    try:
        time0 -= Bi[bcount - 1]
        bcount -= 1
        allc -= 1
    except IndexError:
        pass
    try:
        while time0 + Ai[ci] <= time_:
            time0 += Ai[ci]
            allc += 1
            ci += 1
            cip += 1
            if hic < allc:
                hic = allc
    except IndexError:
        break

print(hic)

Submission status: Wrong Answer

Solution code:
from statistics import mean
N,M,K=map(int, input().split())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
k=0
c=0
while k <= K:
    if len(a) > 0 and len(b)>0:
        if mean(a[:3]) < mean(b[:3]) and ((k+a[0]) <=K):
            k+=a[0]
            c+=1
            a.pop(0)
        elif mean(a[:3]) > mean(b[:3]) and ((k+b[0]) <=K):
            k+=b[0]
            c+=1
            b.pop(0)
        else:
            if (a[0] < b[0]) and ((k+a[0]) <=K):
                k+=a[0]
                c+=1
                a.pop(0)

            elif (a[0] > b[0]) and ((k+b[0]) <=K):
                k+=b[0]
                c+=1
                b.pop(0)
            else:
                break
    elif (len(a) > 0) and (len(b) ==0):
        if ((k+a[0]) <=K):
            k+=a[0]
            c+=1
            a.pop(0)
        else:
            break
    elif (len(b) > 0) and (len(a) ==0):
        if ((k+b[0]) <=K):
            k+=b[0]
            c+=1
            b.pop(0)
        else:
            break
    else:
        break
print(c)

Submission status: Wrong Answer

Solution code:
N,M,K=input().split()
A=input().split()
B=input().split()
A.append(10**9)
B.append(10**9)
#print(N,M,K,A,B)
num=0
Nnum=0
Mnum=0
now_time=0

max_loop=int(M)+int(N)


for i in range(max_loop):
  #print(int(A[Nnum]),int(B[Mnum]))
  if(int(A[Nnum])==int(B[Mnum])):
    if(int(A[Nnum+1])<int(B[Mnum+1])):
      now_time=now_time+int(A[Nnum])
      Nnum=Nnum+1
      num=num+1
    else:
      now_time=now_time+int(B[Mnum])
      Mnum=Mnum+1
      num=num+1
  elif(int(A[Nnum])<int(B[Mnum])):
    now_time=now_time+int(A[Nnum])
    Nnum=Nnum+1
    num=num+1
  else:
    now_time=now_time+int(B[Mnum])
    Mnum=Mnum+1
    num=num+1
  
  if(now_time>int(K)):
    num=num-1
    break
  
  
print(num)