Problem:


Score : 300 points

Problem Statement

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

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

Consider the following action:

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

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

Constraints

1 \leq N, M \leq 200000

1 \leq K \leq 10^9

1 \leq A_i, B_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

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

Output

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

Sample Input 1

3 4 240
60 90 120
80 150 80 150

Sample Output 1

3

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

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

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

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

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

Sample Input 2

3 4 730
60 90 120
80 150 80 150

Sample Output 2

7

Sample Input 3

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

Sample Output 3

0

Watch out for integer overflows.



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


Sample output:
3

Submission status: Wrong Answer

Solution code:
import numpy as np
n,m,k=map(int,input().split())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
A=np.cumsum(np.array(a))
B=np.cumsum(np.array(b))
ans=0
t=0
i=0 #a
j=0 #b
while t<k and i<n and j<m:
    #どっちの机の本を読んでも時間を超えるとき
    if t+a[i]>k and t+b[j]>k:
        break
    #どちらの机にも本があるとき
    if A[i]<B[j]:
        t+=a[i]
        i+=1
    elif A[i]>B[j]:
        t+=b[j]
        j+=1
    if t<=k:
        ans+=1
    #片方の机にしか本がないとき
    if j>=m:
        while t<k:
            t+=a[i]
            i+=1
            if t<=k:
                ans+=1
    elif i>=n:
        while t<k:
            t+=b[j]
            j+=1
            if t<=k:
                ans+=1
print(ans)

Submission status: Wrong Answer

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

A = [i for i in map(int, input().split())]+[10**10]
B = [i for i in map(int, input().split())]+[10**10]

ans = 0
a = 0
b = 0
t = 0
# af = True
# bf = True

while A[a] != 10**10 or B[b] != 10**10:

    if A[a] >= B[b] and t+B[b] <= K:
        t += B[b]
        b += 1
        # if b == len(B):
        #     bf = False
        ans += 1
    elif t+A[a] <= K:
        t += A[a]
        a += 1
        # if a == len(A):
        #     af = False

        ans += 1
    else:
        break

print(ans)


# 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 != len(B) or a != len(A):
#     if b == len(B) and A[a]+t <= K:
#         t += A[a]
#         ans += 1
#         a += 1
#     # else:
#     #     break
#     elif a == len(A) and 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
#     else:
#         t += B[b]
#         ans += 1
#         b += 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()))
la=len(a)
lb=len(b)
suma=sum(a)
sumb=sum(b)
b.reverse()
b.extend(a)

cnt=0
acnt=lb

flag=0
# print(b)
cos=0
for i in range(lb):
    # print(i,sumb)
    if sumb>k:
        sumb-=b[i]
        cnt+=1
    elif sumb<=k:
        break
satu=lb-cnt
ans=lb-cnt
# print(cnt,la)
if sumb+suma<=k:
    print(satu+la)
    exit()

for i in range(la+lb):
    # print(i,sumb,cnt,acnt)
    if sumb>k:
        sumb-=b[cnt]
        cnt+=1
        satu-=1
        if cnt==acnt:
            break
    elif sumb<=k:
        sumb+=b[acnt]
        acnt+=1
        if acnt>=la+lb:
            break
        if sumb<=k:
            satu+=1
    # ans=max(ans,satu)
    # print(sumb,cnt,acnt)
    if sumb<=k:

        sin=acnt-cnt
        cos=max(sin,cos)

print(cos)

Submission status: Wrong Answer

Solution code:
N,M,K=list(map(int,input().split()))
a_list = list(map(int,input().split()))
b_list = list(map(int,input().split()))
totalbook = 0
totaltime = 0
for a in a_list:
  if totaltime+a <= K:
    totaltime+=a
    totalbook+=1
  else:
    break
ans = totalbook
nowaind = totalbook-1 if totalbook > 0 else 0
nowbind = 0
for b in b_list:
  if totaltime+b<=K:
    totaltime+=b
    totalbook+=1
    nowbind+=1
  else:
    break
ans = max(ans,totalbook)
for b in range(nowbind,len(b_list)):
  while nowaind >= 0 and totaltime+b_list[b]>K:
    totalbook-=1
    totaltime-=a_list[nowaind]
    nowaind-=1
  totaltime+=b_list[b]
  if totaltime<=K:
    totalbook+=1
ans = max(ans,totalbook)

totalbook = 0
totaltime = 0
for b in b_list:
  if totaltime+b <= K:
    totaltime+=b
    totalbook+=1
  else:
    break
ans = max(ans,totalbook)

totalbook
nowbind = totalbook-1 if totalbook > 0 else 0
nowaind = 0
for a in a_list:
  if totaltime+a<=K:
    totaltime+=a
    totalbook+=1
    nowaind+=1
  else:
    break
ans = max(ans,totalbook)
print(ans)

Submission status: Wrong Answer

Solution code:
import collections

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

sum_minute = 0
ans = 0
while (sum_minute <= k) and (a or b):
    if a and b:
        if sum_minute + min(a[0], b[0]) <= k:
            if a[0] <= b[0]:
                r = a.pop(0)
                sum_minute += r
                ans += 1
            else:
                r = b.pop(0)
                sum_minute += r
                ans += 1
        else:
            break
    elif not a:
        if sum_minute + b[0] <= k:
            r = b.pop(0)
            sum_minute += r
            ans += 1
        else:
            break
    elif not b:
        if sum_minute + a[0] <= k:
            r = a.pop(0)
            sum_minute += r
            ans += 1
        else:
            break

print(ans)

Submission status: Wrong Answer

Solution code:
N,M,K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
maxa = 0
for i in range(N):
  maxa += A[i]
  if maxa > K:
    maxa -= A[i]
    i -= 1
    break

#Aだけ読み進めるとi+1冊読める
yomeruA = A[:i + 1][::-1]
print(yomeruA)
time = K - maxa
for j in range(M):
  time -= B[j]
  if time < 0:
    j -= 1
    break

#残り時間でBを読み進めるとj+1冊読める
result = i + j + 2
tmpresult = result
time = time + B[j]
for a in yomeruA:
  # Aを１冊諦めたら？
  tmpresult -= 1
  time += a
  for b in B[j:]:
    time -= b
    if time < 0:
      time += b
      break
    else:
      tmpresult += 1
      j += 1
  if tmpresult > result:
    result = tmpresult
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()))
ni = 0
mi = 0
now = 0
count= 0
while True:
    if ni < n and mi < m:
        if a[ni] <= b[mi] and now + a[ni] <= k:
            now += a[ni]
            ni += 1
            count += 1
        elif a[ni] >= b[mi] and now + b[mi] <= k:
            now += b[mi]
            mi += 1
            count += 1
        else:
            break
    elif ni < n:
        if now + a[ni] <= k:
            now += a[ni]
            ni += 1
            count += 1
        else:
            break
    elif mi < m:
        if now + b[mi] <= k:
            now += b[mi]
            mi += 1
            count += 1
        else:
            break
    else:
        break
print(count)

Submission status: Wrong Answer

Solution code:
import sys
import copy
from collections import deque
import collections
stdin = sys.stdin

mod = 10**9+7

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n, m, k = na()

a = na()
b = na()

num_books = 0
sum_time = 0
for i in a:
    if sum_time+i > k:
        break
    num_books += 1
    sum_time += i
# print(num_books)


res = num_books
ia = num_books - 1
ib = 0
while ib < len(b):
    if sum_time < k:
        if sum_time+b[ib] > k:
            break
        sum_time += b[ib]
        ib += 1
        num_books += 1
    else:
        sum_time -= a[ia]
        ia -= 1
        num_books -= 1
    if sum_time <= k:
        res = max(res, num_books)

print(res)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
i = j = 0
r = 0
while i < N and j < M and K >= 0:
    if i >= N:
        K -= B[j]
        j += 1
    elif j >= M:
        K -= A[i]
        i += 1
    else:
        if A[i] < B[j]:
            K -= A[i]
            i += 1
        else:
            K -= B[j]
            j += 1
    r += 1
print(r)

Submission status: Wrong Answer

Solution code:
a = input()
n = input()
m = input()
first = a.split(" ")
N = n.split(" ")
M = m.split(" ")
overflow = 0
for i in N:
    if int(i) >= 10**9:
        overflow = 1
        break
        
for i in M:
    if int(i) >= 10**9:
        overflow = 1
        break
if int(first[0]) >= 200000 or int(first[1]) >= 200000:
    overflow = 1
if int(first[2]) >= 10**9:
    overflow = 1
         
if overflow == 0:
    totaltime = 0
    count = 1
    for i in range(int(first[1]) + int(first[0])):
      if i == 6:
        break
      if  len(N) != 0 and len(M) != 0:
        if totaltime + int(N[0]) > int(first[2]) or totaltime + int(M[0]) > int(first[2]):
          break
      if len(N) == 0:
        totaltime += int(M[0])
        M.remove(M[0])
        count += 1
        if totaltime > int(first[2]):
          break
      elif len(M) == 0:
        totaltime += int(N[0])
        N.remove(N[0])
        count += 1
        if totaltime > int(first[2]):
          break
      elif int(N[0]) < int(M[0]):
        totaltime += int(N[0])
        N.remove(N[0])
        count += 1
      elif int(M[0]) < int(N[0]):
        totaltime += int(M[0])
        M.remove(M[0])
        count += 1
    print(count)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
book = list()
ans = 0
for i in range(n + m):
    try:
        book.append(a.pop(0) if a[0] < b[0] else b.pop(0))
    except:
        book.extend(a)
        book.extend(b)
        break
for i in range(n + m):
    if book[i] > k:
        break
    k -= book[i]
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
la=list(map(int,input().split()))
lb=list(map(int,input().split()))
lla=[]
counta=0
for i in la:
    counta+=i
    lla.append(counta)
countb=0
llb=[]
for j in lb:
    countb+=j
    llb.append(countb)
for i in range(n):
    if lla[i]>k:
        break
if lla[n-1]<=k:
    book=n
    num=n-1
elif lla[n-1]>k and i==n-1:
    book=n-1
    num=n-2
else:
    num=i
    book=i
num=i
while num>=0 and book<m+n and book-num-1<=m-1:
    if num!=0:
        if lla[num]+llb[book-num-1]<=k:
            book+=1
        else:
            num-=1
    elif num==0:
        if llb[book-num-1]<=k:
            book+=1
        else:
            num-=1

print(book)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
total = 0
ac = 0
bc = 0
alen = len(a)
blen= len(b)
allbook = alen + blen
count = 0
while True:
  if k < total:
    count -= 1
    break
  if total == k:
    break
  if bc < blen:
    if ac < alen and a[ac] <= b[bc]:
      total += a[ac]
      ac += 1
      count += 1
      continue
    else:
      total += b[bc]
      bc += 1
      count += 1
      continue
  if ac < alen:
    if bc < blen and a[ac] >= b[bc]:
      total += b[bc]
      bc += 1
      count += 1
      continue
    else:
      total += a[ac]
      ac += 1
      count += 1
      continue
  break
print(count)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
l1=list(map(int,input().split()))
l2=list(map(int,input().split()))
l1.append(100000000000)
l2.append(100000000000)
val=0
i=0
j=0
temp=0
for i in range(n+m):
    if(val<k):
        if(l1[0]<l2[0]):
            val+=l1[0]
            i+=1
            l1.remove(l1[0])
            temp+=1
        elif(l1[0]>l2[0]):
            val+=l2[0]
            j+=1
            l2.remove(l2[0])
            temp+=1
    else:
        break
if(val<=k):
    print(temp)
else:
    print(temp-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()))
a.reverse()
b.reverse()
ans = 0
for i in range(n+m):
    if (a != [] and b != []):
        some = min(a[-1], b[-1])
    elif a != [] and b == []:
        some = a[-1]
    elif (a == [] and b != []):
        some = b[-1]
    else:
        break
    if (k - some < 0):
        break;
    else:
        ans+=1
        k -= some
        if some in a:
            a.pop()
        else:
            b.pop();
    
print(ans)

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

n,m = 0,0
ans = 0
pre = 0
cnt =0
while ans<=K:
    if n>=N or m>=M:
        break
    if A[n] < B[m]:
        ans += A[n]
        pre = A[n]
        n+=1
        cnt +=1
    else:
        ans += B[m]
        pre = B[m]
        m+=1
        cnt += 1

if n==N and m<M:
    while ans<=K:
        if m>=M:
            break
        ans += B[m]
        pre = B[m]
        m+=1
        cnt += 1
elif n<N and m==M:
    while ans<=K:
        if n>=N:
            break
        ans += A[n]
        pre = A[n]
        n+=1
        cnt += 1
if ans>K:
    ans -= pre
    cnt -=1

print(cnt)

Submission status: Wrong Answer

Solution code:
import sys
import collections

rm = lambda: map(int, sys.stdin.buffer.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')

n, m, k = rm()
a = rl()
b = rl()

cnt = 0
dp = [[inf]*(len(b) + 5) for _ in range(len(a) + 5)]
dp[0][0] = 0
dp[0][1] = b[0]
dp[1][0] = a[0]
for i in range(len(a)):
    for j in range(len(b)):
        dp[i+1][j+1] = min(dp[i][j+1] + a[i], dp[i+1][j] + b[j])
        if dp[i+1][j+1] <= k:
            cnt = max(i+j+2, cnt)

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()))
i,j,ans,tmp = 0,0,0,0
while A or B:
    if i >= N and j >= M:break
    elif i < N and j >= M:
        if tmp+A[i] <= K:
            ans += 1
            tmp += A[i]
        i += 1
    elif i >= N and j < M:
        if tmp+B[j] <= K:
            ans += 1
            tmp += B[j]
        j += 1
    elif A[i] < B[j]:
        if tmp+A[i] <= K:
            ans += 1
            tmp += A[i]
        i += 1
    else:
        if tmp+B[j] <= K:
            ans += 1
            tmp += B[j]
        j += 1
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()))

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

print(count-1)

Submission status: Wrong Answer

Solution code:
import sys
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
lastime = 0
ans_list = []
a.insert(0,0)
for i in range(n+1):
  time = lastime + a[i]
  lastime = lastime + a[i]
  book = i
  if time <= k:
    ans_list.append(book)
  else:
    break
  for j in range(m):
    time = time + b[j]
    book = book + 1
    if time <= k:
      ans_list.append(book)
  else:
    break
  time = lastime
if len(ans_list) == 0:
  ans = n + m
else:
  ans = max(ans_list)
print(ans)

Submission status: Wrong Answer

Solution code:
def main ():
    X = input()
    X = X.split(' ')
    N = int(X[0])
    M = int(X[1])
    K = int(X[2])
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
  
    total = 0
    posA = 0
    posB = 0
    time = 0
    z = 0
    while z == 0:
        if posA < len(A) and A[posA] < B[posB]:
            if time + A[posA] <= K:
                time += A[posA]
                if posA < len(A) - 1:  
                    posA += 1
                total += 1
            else:
                print(total)
                return
        elif  posB < len(B) and A[posA] > B[posB]:
            if time + B[posB] <= K:
                time += B[posB]
                if posB < len(B) - 1:
                    posB += 1
                total += 1
            else:
                print(total)
                return
        else:
            print(0)
            return
main ()

Submission status: Wrong Answer

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

minute=0
books=0
an=a.pop(0)
bn=b.pop(0)

while minute < root[2]:
    books += 1
    if an < bn:
        minute += an
        if len(a) != 0:
            an = a.pop(0)
        else:
            an = 1000000000
    elif bn < an:
        minute += bn
        if len(b) != 0:
           bn = b.pop(0) 
        else:
            bn = 1000000000
    else:
        minute += an
        if len(a) != 0:
            an = a.pop(0)
        elif len(b) != 0:
           bn = b.pop(0) 
        else:
            pass

print(books-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()))
import bisect

class Cumulative_Sum:
    def __init__(self, a):
        la = len(a)
        self.s = [0] * (la + 1)
        for i in range(la):
            self.s[i+1] = self.s[i] + a[i]
    # s[l]からs[r]までの和
    def sum(self, l, r):
        return self.s[r] - self.s[l]
csa = Cumulative_Sum(a)
csb = Cumulative_Sum(b)
#print(csa.s)
#print(csb.s)
ans = 0
for i in range(len(csa.s)):
    t = csa.s[i]
    #if t > k:
    #    continue
    p = max(0, k - t)
    bi = bisect.bisect_left(csb.s, p)
    if csb.s[m] <= p:
        ans = max(ans, i + m)
    else:
        ans = max(ans, i + bi-1)

print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    from bisect import bisect_right

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

    def accumulate(a):
        s = 0
        # yield s
        for x in a:
            s += x
            yield s

    *P, = accumulate(A)
    *Q, = accumulate(B)

    ans = 0
    for i, pi in enumerate(P, start=1):
        rest = K - pi
        if rest < 0: break
        j = bisect_right(Q, rest)
        ans = max(ans, i + j)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:

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

ans = 0
for x in range(1, nmk[0]+nmk[1]+1):

    if not A:
        if ans +B[0] >= nmk[2]:
            break
        ans += B.pop(0)
    
    elif not B:
        if ans + A[0] >= nmk[2]:
            break
        ans += A.pop(0)
        
    elif A[0] <= B[0]:
        if ans + A[0] >=nmk[2]:
            x -= 1
            break
        ans += A.pop(0)
        
    elif B[0] <= A[0]:
        if ans + B[0] >= nmk[2]:
            x -= 1
            break
        ans += B.pop(0)

print(x)

Submission status: Wrong Answer

Solution code:
import collections as cs

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

A.append(K + 1)
B.append(K + 1)

count = 0
time = 0
num = len(A) + len(B)

for i in range(num):
    if A[0] <= B[0]:
        if A[0] + time <= K:
            time += A.popleft()
            count += 1

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

print(count)

Submission status: Wrong Answer

Solution code:
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
A.append(10**9)
B = list(map(int,input().split()))
B.append(10**9)
aa = 0
bb = 0
while aa < K:
  aa += min(A[0],B[0])
  if aa > K:
    break
  bb += 1
  if A[0] > B[0]:
    del B[0]
  else:
    del A[0]
print(bb)

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
count = 0
i = 0
j = 0
A = a[0]
B = b[0]
while True:
    if A<=B:
        time += A
        i += 1
        if i < n:
            A = a[i]
        else:
            A = 10 ** 10
    else:
        time += B
        j += 1
        if j < m:
            B = b[j]
        else:
            B = 10 ** 10
    if time > k:
        break
    count += 1
    if i == n and j == m:
        break

print(count)

Submission status: Wrong Answer

Solution code:
N = input().split(" ")
A= input().split(" ")
B= input().split(" ")
A.extend(B)
A_int = [int(n) for n in A]
A_int.sort(reverse=False)
#C = A.sort()
#print(A_int)
cont = 0

#N[2]これが合計所要時間のまっくす

for i in range(len(A_int)):
  N[2] = int(N[2]) - A_int[i]
  if N[2] > -1:
    cont = cont + 1
  else:
    break
print(cont)

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_a = len(a) -1
rwa = 0
for i,e in enumerate(a):
    rwa += e
    if rwa > k:
        rwa -= e
        i_a = i - 1
        break
rwb = k - rwa
i_b = 0
mx = i_a + 1
for j,e in enumerate(b):
    if rwb >= e:
        i_b += 1
        mx = max(mx,i_a + 1 + i_b)

        rwb -= e
        continue
    else:
        if i_a < 0 :
            break
        rwb += a[i_a]
        i_a -= 1
print(mx)

Submission status: Wrong Answer

Solution code:
#input = raw_input

map_ = lambda x, y: list(map(x, y))

n, m, k = map_(int, input().split(" "))
As = map_(int, input().split(" "))
Bs = map_(int, input().split(" "))

ai = 0
bi = 0
cost = 0
flag = True
count = 0
a = As[ai]
b = Bs[bi]

cur = 0
a_cumsum = []
for i in range(n):
    cur += As[i]
    if cur > k:
        n = i
        break
    else:
        a_cumsum.append(cur)

cur = 0
b_cumsum = []
for i in range(m):
    cur += Bs[i]
    if cur > k:
        m = i
        break
    else:
        b_cumsum.append(cur)
#print("n", n)
#print("m", m)
#print(a_cumsum)
#print(b_cumsum)

out = 0
end = False
for i in reversed(range(n)):
    a_count = i +1
    cur = a_cumsum[i]
    cur_count = None
    
    for j in reversed(range(m)):
        b_count = j + 1
        cur2 = cur + b_cumsum[j]
        if cur2 <= k:
            if b_count == m:
                end = True
            cur_count = a_count + b_count
            #print(i, a_count, b_count)
            break
    
    if cur_count is None:
        cur_count = a_count
        #print(i, a_count, 0)
    out = max(out, cur_count)

    if end:
        break

print(out)

Submission status: Wrong Answer

Solution code:
from collections import deque as q
import bisect

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

c=0
for i in range(N+M):
    if len(As)==0:
        book=Bs.pop()
    elif len(Bs)==0:
        book=As.pop()
    else:
        if As[-1] < Bs[-1]:
            book=As.pop()
        elif As[-1] > Bs[-1]:
            book=Bs.pop()
        else:
            At=As[::-1]
            Bt=Bs[::-1]
            n=min(len(At),len(Bt))
            for j in range(n):
                if At[:j+1]!=Bt[:j+1]:
                    break
            if At[:j+1]>Bt[:j+1]:
                book=Bs.pop()
            else:
                book=As.pop()

    c+=book
    #print(i,book,c)
    if c > K:
        break
else:
    i+=1
print(i)

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_i = 0
b_i = 0
count = 0
while(K>0):
    if a_i == N and b_i == M:
        break
    elif a_i == N:
        K -= B[b_i]
        b_i += 1
        count+=1
    elif b_i == M:
        K -= A[a_i]
        a_i += 1
        count+=1
    else:
        if A[a_i]<B[b_i]:
            K -= A[a_i]
            a_i += 1
        else:
            K -= B[b_i]
            b_i += 1
        count+=1
    if K<0:
        count-=1
print(count)

Submission status: Wrong Answer

Solution code:
import bisect
import numpy

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

cost_a = numpy.insert(numpy.cumsum(a), 0, 0)
cost_b = numpy.insert(numpy.cumsum(b), 0, 0)

left_max = bisect.bisect_left(cost_a, k)
right_max = bisect.bisect_left(cost_b, k)

ans = 0
for i in range(left_max):
    for j in range(right_max):
        if cost_a[i] + cost_b[j] <= k:
            ans  = i + j if ans < i + j else ans
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()))
cntA = 0
ans = 0
p = max(m,n)
if p == n:
  q = a
  r = b
else:
  q = b
  r = a
for i in range(p):
  if cntA+q[i] > k:
    break
  ans += 1
  cntA += q[i]
indA = ans-1
for i in range(indA+1):
  temp = 0
  for v in r:
    if cntA + v > k:
      break
    cntA += v
    temp += 1
  cntA -= q[indA-i]
  ans = max(ans,indA+1+temp)
  indA -= 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()))
temp=0
an,bn=0,0
ans=0
flag=0
cnt=0
while temp<=k:
    if an==n and bn==m: break
    if an>=n:
        if flag:
            bn-=cnt
            flag=0
        temp+=b[bn]
        if temp>k: break
        bn+=1
    elif bn>=m:
        if flag:
            an-=cnt
            flag=0
        temp+=a[an]
        if temp>k: break
        an+=1
    else:
        if a[an]<b[bn]:
            if flag:
                bn-=cnt
                flag=0
            temp+=a[an]
            if temp>k: break
            an+=1
        elif a[an]>b[bn]:
            if flag:
                an-=cnt
                flag=0
            temp+=b[bn]
            if temp>k: break
            bn+=1
        else:
            temp+=a[an]
            if temp>k: break
            flag=1
            an+=1
            bn+=1
            cnt+=1
    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.append(10**19)
b.append(10**19)

i, j = 0, 0
ans = 0
time = 0

for _ in range(m+n):
    s, t = a[i], b[j]

    # print(f'{s} {t}')
    # print(f'{i} {j}')

    if s <= t and i < n:
        i += 1
        time += s
        # ans += 1

    if s > t and j < m:
        j += 1
        time += t
    

    if time > k:
        break

    ans += 1


# mn = min(a[0], b[0])
# k -= mn

# while time <= k:
#     # print(f'{i} {j}')
#     s, t = a[i], b[j]
    
#     mn = min(s, t)

#     if s <= t and i < n-1:
#         i += 1
#     if s > t and j < m-1:
#     # else:
#         j += 1

#     time += mn

#     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()))
count = 0
i = 0
j = 0
while k >= a[i] or k >= b[j]:
    read = min(a[i],b[j])
    if read == a[i]:
        i += 1
        count += 1
        k -= read
        if i == n:
            a.append(10**10)
    else:
        j += 1
        count += 1
        k -= read
        if j == m:
            b.append(10**10)
print(count)

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
N, M, K = map(int, input().split())
A = deque([int(i) for i in input().split()])
B = deque([int(i) for i in input().split()])
if sum(A) + sum(B) <= K:
    print(N+M)
    sys.exit()
cur = 0
ans = 0
while cur < K and ans < N+M:
    if len(A) != 0 and len(B) != 0:
        a = A.popleft()
        b = B.popleft()
        if a <= b:
            cur += a
            if cur > K:
                break
            B.appendleft(b)
            ans += 1
        else:
            cur += b
            if cur > K:
                break
            A.appendleft(a)
            ans += 1
    elif len(A) == 0:
        b = B.popleft()
        cur += b
        if cur > K:
            break
        ans += 1
    elif len(B) == 0:
        a = A.popleft()
        cur += a
        if cur > K:
            break
        ans += 1
print(ans)

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.append(10**10)
b.append(10**10)
cnt_a=0
cnt_b=0
while True:
    if a[cnt_a] < b[cnt_b]:
        if k >= a[cnt_a]:
            k -= a[cnt_a]
            cnt_a += 1
        else:
            break
    else:
        if k >= b[cnt_b]:
            k -= b[cnt_b]
            cnt_b += 1
        else:
            break
print(cnt_a + cnt_b)

Submission status: Wrong Answer

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

r0=0
rr = 0
t0=0
i = 0
j = 0
flag = 0

while t0<=K:
    t0 = t0 + A[i]
    if t0<=K:
        r0 = r0 + 1
        if i==N-1:
            break
        i = i + 1

if t0>K:
    t0 = t0 - A[i]

while t0<=K:
    t0 = t0 + B[j]
    if t0<=K:
        r0 = r0 + 1
        if j==M-1:
            flag = 1
            break
        j = j + 1

if t0>K:
    t0 = t0 - B[j]

rr = r0
Kk = K
tk = t0
rk = r0

for k in range(i):
    if flag == 1:
        break
    Kk = Kk + A[i-k] - tk
    tk = 0
    ik = 0
    rk = rk - 1
    while tk<=Kk:
        tk = tk + B[j]
        if tk<=Kk:
            rk = rk + 1
            if j == M-1:
                flag = 1
                break
            j = j+1
    rr = max(rk,rr)


print(rr)

Submission status: Wrong Answer

Solution code:
N,M,K = map(int,input().split())
A = []
B = []
A = input().split()
B = input().split()
XA = 0
XB = 0
TI = 0
for i in range(N+M):
  if XA == N:
    if (TI + int(B[XB]))<= K:
      TI = TI + int(B[XB])
      XB = XB +1
    else:
      break
  elif XB == M:
    if (TI + int(A[XA]))<= K:
      TI = TI + int(A[XA])
      XA = XA +1
    else:
      break
  else:
    if int(A[XA]) <= int(B[XB]):
      if (TI + int(A[XA]))<= K:
        TI = TI + int(A[XA])
        XA = XA +1
      else:
        break
    else:
      if (TI + int(B[XB]))<= K:
        TI = TI + int(B[XB])
        XB = XB +1
      else:
        break
print(XA+XB)