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 os
import sys
from collections import defaultdict, Counter, deque
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush,heapify
from math import ceil, floor, sqrt
from copy import deepcopy

def main():
    
    n,m,k = map(int, input().split())
    n_list = list(map(int, input().split()))
    m_list = list(map(int, input().split()))
    i,j,count = 0,0,0
    while(k>0):
        if count == n+m:
            break
        if n_list[i] < m_list[j]:
            k -= n_list[i]
            count += 1
            i += 1
        else:
            k -= m_list[j]
            count += 1
            j +- 1
        
        if k < 0:
            count -= 1

    print(count)



            

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#!usr/bin/env pypy3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)

def main():
    N, M, K = LI()
    A = LI()
    B = LI()

    i, j, ans, cum = 0, 0, 0, 0

    while True:
        if i < N and j < M:
            if cum + A[i] <= K and cum + B[j] <= K:
                if A[i] <= B[j]:
                    cum += A[i]
                    i += 1
                else:
                    cum += B[j]
                    j += 1
            elif cum + A[i] <= K:
                cum += A[i]
                i += 1
            elif cum + B[j] <= K:
                cum += B[j]
                j += 1
            else:
                break
            ans += 1
        elif i < N:
            if cum + A[i] <= K:
                cum += A[i]
                i += 1
                ans += 1
            else:
                break
        elif j < M:
            if cum + B[j] <= K:
                cum += B[j]
                j += 1
                ans += 1
            else:
                break
        else:
            break


    print(ans)

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をi冊読む
sum_a = [0]*n
sum_b = [0]*m
sum_a[0] = a[0]
sum_b[0] = b[0]
for i in range(1, n):
    sum_a[i] = sum_a[i-1]+a[i]
for i in range(1, m):
    sum_b[i] = sum_b[i-1]+b[i]

def binary_search(list, item):
    low = 0
    high = len(list) - 1
    if list[high] <= item:
        return high+1
    if list[low] > item:
        return low
    while True:
        mid = (low + high) //2
        guess = list[mid]
        if high - low == 1:
            return high
        if guess > item:
            high = mid
        else:
            low = mid

ans = 0
for i in range(n):
    tmp_ans = i+1
    tmp_k = k-sum_a[i]
    # print(i, tmp_k)
    if tmp_k <= 0:
        pass
    else:
        b_index = binary_search(sum_b, tmp_k)
        tmp_ans += b_index
        # print('a', i, b_index)
        if tmp_ans > ans:
            ans = tmp_ans

tmp_ans = 0
if sum_b[0] <= k:
    tmp_ans = binary_search(sum_b, k)
if tmp_ans > ans:
    ans = tmp_ans
print(ans)

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()))
A2 = []
sum_ = 0
c = 0
for a in A:
  if c+a > X:
    break
  c += a
  A2.append(a)
sum_ += c
B2 = []
c = 0
for b in B:
  if c+b > X:
    break
  c += b
  B2.append(b)
sum_ += c

while True:
  if sum_ <= X:
    break
  if A2[-1] > B[-1]:
    a = A2.pop()
    sum_ -= a
  else:
    b = B2.pop()
    sum_ -= b
print(len(A2)+len(B2))

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

Submission status: Wrong Answer

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

da = []
da.append([a[0], 1])
now = 0
for i in range(1,N):
    if a[i] == a[i-1]:
        da[now][1] += 1
    else:
        da.append([a[i], 1])
        now += 1
db = []
db.append([b[0], 1])
now = 0
for i in range(1,M):
    if b[i] == b[i-1]:
        db[now][1] += 1
    else:
        db.append([b[i], 1])
        now += 1

Na = len(da); Mb = len(db)
ai = 0; bi = 0

dp = [0 for i in range(M+N+1)]

for i in range(1, N+M+1):
    if ai == Na:
        res = db[bi][0]
        db[bi][1] -= 1
        if db[bi][1] == 0:
            bi += 1
    elif bi == Mb:
        res = da[ai][0]
        da[ai][1] -= 1
        if da[ai][1] == 0:
            ai += 1

    elif da[ai][0] == db[bi][0]:
        ra = ai; rb = bi
        while da[ra][0] == da[rb][0]:
            ra += 1; rb += 1
            if ra == Na or rb == Mb:
                res = da[ai][0]
                da[ai][1] -= 1
                if da[ai][1] == 0:
                    ai += 1
                break
            if da[ra][0] < da[rb][0]:
                res = da[ai][0]
                da[ai][1] -= 1
                if da[ai][1] == 0:
                    ai += 1
                break
            elif da[ra][0] < da[rb][0]:
                res = db[bi][0]
                db[bi][1] -= 1
                if db[bi][1] == 0:
                    bi += 1
                break

    elif da[ai][0] < db[bi][0]:
        res = da[ai][0]
        da[ai][1] -= 1
        if da[ai][1] == 0:
            ai += 1
    else:
        res = db[bi][0]
        db[bi][1] -= 1
        if db[bi][1] == 0:
            bi += 1

    dp[i] = dp[i-1] + res

#print(dp)

import bisect
print(bisect.bisect_right(dp, K)-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()))
c = []
nn, mm = 0, 0

for _ in range(n+m):
    if n == 0:
        c += b[mm:]
        break
    elif m == 0:
        c += a[nn:]
        break

    if a[nn] < b[mm]:
        c.append(a[nn])
        nn += 1
    else:
        c.append(b[mm])
        mm += 1
    if nn == n:
        c += b[mm:]
        break
    elif mm == m:
        c += a[nn:]
        break

ans = 0
for i in range(len(c)):
    k -= c[i]
    if k < 0:
        break
    else:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n,m,k = map(int, input().split())
an = list(map(int, input().split()))
bn = list(map(int, input().split()))
book = n + m
nokori = k
Ans = 0
an.append(1000000000)
bn.append(1000000000)
for i in range(book):
    if an[0] <= bn[0]:
        nokori = nokori - an[0]
        del an[0]
    elif an[0] > bn[0]:
        nokori = nokori - bn[0]
        del bn[0]
    if nokori < 0:
        break
    Ans = 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]*(n+1)
B=[0]*(m+1)
c = 0
#累積和
for i in range(n):
    A[i+1] = A[i] + a[i]
for i in range(m):
    B[i+1] = B[i] + b[i]
#
for i in range(n+1):
    if A[i]>k:
        bookA=i-1
        timeA = A[i-1]
        break
else:
    bookA = n
    timeA = A[n]
    
for i in range(m+1):
    if B[i] >k:
        bookB = i-1
        timeB = B[i-1]
        break
else:
    bookB = m
    timeB = B[m]
#
"""
print(bookA,timeA,)
print(bookB,timeB)
if bookA == 0 and bookB == 0:
    print(0)
    exit()
"""
if bookA < bookB:
    time = timeB
    book = bookB
    for i in range(n+1):
        if k-time < A[i]:
            break
        c = i
    else:
        c = n
    book += c 

elif bookA > bookB:
    book = bookA
    time = timeA
    for i in range(m+1):
        if k-time < B[i]:
            break
        c = i
    else:
        c = m
    book += c

else:
    if timeA > timeB:
        time = timeB
        book = bookB
        for i in range(n+1):
            if k-time < A[i]:
                break
            c = i
        book += c
    elif timeB > timeA:
        time = timeA
        book = bookA
        for i in range(m+1):
            if k-time < B[i]:
                break
            c = i
        book += c
        print(c)
    else:
        if A[bookA-1] > B[bookB-1]:
            book = bookB-1
            for i in range(n+1):
                if A[i] > k:
                    break
                c = i
            book += c
        elif A[bookA-1] < B[bookB-1]:
            book = bookA-1
            for i in range(m+1):
                if B[i] > k:
                    break
                c = i
            book += c
        else:
            book = bookA
            for i in range(m+1):
                if k-timeA < B[i]:
                    book += i-1
            else:
                book += m
if book < 0:
    print(0)
else:
    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()))

S = [0]

Sum = 0


for i in range(N):
  K = K - A[i]
  if K >= 0:
    Sum += 1
  else:
    K = K + A[i]
    break
S.append(Sum)

for j in range(M):
  K = K - B[j]
  if K >= 0:
    Sum += 1
  else:
    if i == 0:
      break
    for k in range(i):
      K = K + A[i-k-1]
      Sum = Sum - 1
      if K >= 0:
        break
    if K >= 0:
      Sum += 1
    else:
      break
  S.append(Sum)
print(max(S))

Submission status: Wrong Answer

Solution code:
import bisect
import sys
import math
from collections import deque
from heapq import heappush, heappop

def sRaw():
    return input().rstrip("\r")


def iRaw():
    return int(input())


def ssRaw():
    return input().split()


def isRaw():
    return list(map(int, ssRaw()))


INF = 1 << 29

#DIV = (10**9) + 7
DIV = 998244353

def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)


def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def CONV_TBL(max, mod=DIV):
    fac, finv, inv = [0]*max, [0]*max, [0]*max
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, max):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod - inv[mod % i] * (mod//i) % mod
        finv[i] = finv[i-1]*inv[i] % mod

    class CONV:
        def __init__(self):
            self.fac = fac
            self.finv = finv
            pass

        def ncr(self, n, k):
            if(n < k):
                return 0
            if(n < 0 or k < 0):
                return 0
            return fac[n]*(finv[k]*finv[n-k] % DIV) % DIV

    return CONV()


def cumsum(As):
    s = 0
    for a in As:
        s += a
        yield s


sys.setrecursionlimit(200005)


def dijkstra(G,start=0):
    heap = []
    cost = [INF]*len(G)
    heappush(heap,(0,start))
    while len(heap)!=0:
        c,n = heappop(heap)
        if cost[n] !=INF:
            continue
        cost[n]=c
        for e in G[n]:
            ec,v = e
            if cost[v]!=INF:
                continue
            heappush(heap,(ec+c,v))
    return cost


def main():
    N,M,K = isRaw()
    As = isRaw()
    Bs = isRaw()
    sAs = [0]
    for a in As:
        t = a + sAs[-1]
        if t>K:
            break
        sAs.append(t)

    sBs=[0]
    for b in Bs:
        t = b + sBs[-1]
        if t>K:
            break
        sBs.append(t)

    ans = 0
    for sai,sa in enumerate(sAs):
        sbi=0
        if len(sBs)>1:
            sbi = bisect.bisect_left(sBs,K-sa)
        
        ans = max(ans,sai+sbi)
    print (ans)


main()

Submission status: Wrong Answer

Solution code:
import itertools
N, M, K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
Ac = list(itertools.accumulate(A))
Bc = list(itertools.accumulate(B))
amax, bmax = 0, 0
for i in range(len(A)):
    if Ac[i] <= K:
        amax = i + 1
    else: break
if amax == 0:
    At = 0
else:
    At = Ac[amax - 1]
for i in range(len(B)):
    if Bc[i] + At <= K:
        bmax = i + 1
    else: break
ans = amax + bmax
if amax > 0:
    for i in range(1, amax):
        anow = amax - i
        At = Ac[anow - 1]
        for j in range(bmax-1, len(B)):
            if Bc[j] + At <= K:
                bmax = j + 1
            else: break
        ans = max(ans,anow+bmax)
bmaxr = 0
for i in range(len(B)):
    if Bc[i] <= K:
        bmaxr = i + 1
    else: break
ans = max(ans, bmaxr)
print(ans)

Submission status: Wrong Answer

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

t = 0
s = 0

while t < K:
  s = s+1
  if A[0] < B[0]:
    t = t + A[0]
    del A[0]
    if len(A) == 0:
      A.append(1000000000)
  else:
    t = t + B[0]
    del B[0]
    if len(B) == 0:
      B.append(100000000)
    

if t == K:
  print(s)
else:
  print(s-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()))

ai =0
bi=0
st =0
c = 0
while True:
  if ai == N:
    if bi == M:
      break
    else:
      st += b[bi]
      if st > K:
        break
      bi += 1
      c +=1
  elif bi == M:
    if ai == N:
      break
    else:
      st += a[ai]
      if st > K:
        break
      ai += 1
      c += 1
  elif a[ai] > b[bi]:
    st += b[bi]
    if st > K:
      break
    bi +=1
    c +=1
  elif a[ai] < b[bi]:
    st += a[ai]
    if st > K:
      break
    ai +=1
    c +=1
  elif a[ai] == b[bi]:
    tmpst = st
    tmpc =0
    tmpai = ai
    tmpbi = bi
    while True:
      tmpst +=a[tmpai]
      if tmpai < N-1:
        tmpai+=1
      if tmpbi < M-1:
        tmpbi+=1
      if tmpst > K:
        st += a[ai]
        if st > K:
          print(c)
          exit()
        ai +=1
        c +=1
        #print(c+tmpc,'ja')
        #exit()
      if a[tmpai] > b[tmpbi]:
          st += b[bi]
          if st > K:
              print(c)
              exit()
          bi += 1
          c += 1
          break
      elif a[tmpai] < b[tmpbi]:
          st += a[ai]
          if st > K:
              print(c)
              exit()
          ai += 1
          c += 1
          break
      if tmpai == N-1 and tmpbi == M-1:
        st += a[ai]
        if st > K:
          print(c)
          exit()
        ai += 1
        c += 1
        break
      #print(tmpst)
      tmpc += 1
      #print(tmpai, tmpbi)
print(c)

Submission status: Wrong Answer

Solution code:
from itertools import *
from bisect import bisect_right
n,m,time = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

A = [0]+list(accumulate(a))
B = [0]+list(accumulate(b))


for i in range(bisect_right(A, time)-1,-1,-1):
    for j in range(bisect_right(B, time)-1,-1,-1):
        if A[i] + B[j] <= time:
            print(i+j)
            exit()
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()))

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 (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
      
      
print(max(ans_list))

Submission status: Wrong Answer

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

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

n = N-1
m = M-1
cnt = N + M

while True:
    if A[n] > B[m]:
        n - 1
        total -= A[n]
        cnt -= 1
    else:
        m - 1
        total -= B[m]
        cnt -= 1
    
    if total <= K:
        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()))

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] and k>=b[j]:
      total.append(b[j])
      k = k-b[j]
      j+=1
    elif b[j]>=a[i] and k>=a[i]:
      total.append(a[i])
      k=k-a[i]
      i+=1
  elif i>=len(a) and k>=j:
    total.append(b[j])
    k = k-b[j]
    j+=1
  elif j>=len(b) and k>=i:
    total.append(a[i])
    k=k-a[i]
    i+=1
print(total)

Submission status: Wrong Answer

Solution code:
S=lambda:input()
I=lambda:int(input())
L=lambda:list(map(int,input().split()))
LS=lambda:list(map(str,input().split()))

import sys
input=sys.stdin.readline
n,m,k=L()
a=L()
b=L()
ans=0
maxi=n+m
time=0
ai=0
bi=0

for i in reversed(range(n+1)):
    if sum(a[:i])>k:
        continue
    time=sum(a[:i])
    if time+b[0]>k:
        ans=ans if ans>i else i
        continue
    if time+sum(b[:m])<=k:
        ans=ans if ans>i+m else i+m
        continue
    
    ok=0
    ng=m
    while(abs(ok-ng)>1):
        print(ok)
        mid=(ok+ng)//2
        if time+sum(b[:mid])<=k:
            ok=mid
        else:
            ng=mid
    ans=ans if ans>i+ok else i+ok
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()))
o = n + m
if sum(a+b) <= k:
    print(n+m)
    exit()
a_l = int(len(a))
b_l = int(len(b))
if a_l < b_l:
    c = b_l - a_l
    a = a + [10 ** 10 for i in range(c)]
elif b_l < a_l:
    c = a_l - b_l
    b = b + [10 ** 10 for i in range(c)]
t = 0
#print(a,b)
for i in range(o):
    #print(a)
    if a[0] < b[0]:
        t += a[0]
        del a[0]
    else:
        t += b[0]
        del b[0]
    #print(a[0],b[0])
    #print(t)
    if t > k:
        print(i)
        break

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(len(A)+len(B)+2):
  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 == len(A):
    for _ in range(len(B)+1-b):
      if b == len(B):
        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 == len(B):
    for _ in range(len(A)+1-a):
      if a == len(A):
        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:
import random
n, m, k = map(int, input().split())
# n, m, k = random.randint(1, 10**5), random.randint(1, 10**5), random.randint(10**7, 10**8)
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
# a_list = [random.randint(1, 10**2) for i in range(n)]
# b_list = [random.randint(1, 10**2) for i in range(m)]
# print(n,m,k)
# print(a_list[0], b_list[0])
a_sum = [0]
b_sum = [0]
max_a = 0
max_b = 0
for i in range(1, max(n+1, m+1)):
    if i < n+1:
        a_sum.append(a_sum[i-1] + a_list[i-1])
        if a_sum[i] < k:
            max_a = i
    if i < m+1:
        b_sum.append(b_sum[i-1] + b_list[i-1])

max_num = max_a
# print(max_a)
while max_a > -1:
    while max_b < m and b_sum[max_b+1] <= k-a_sum[max_a]:
        max_b += 1
    if max_num < max_a + max_b:
        max_num = max_a + max_b
        # print(max_a, max_b)
    max_a -= 1

print(max_num)
# print(n+m)

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

Submission status: Wrong Answer

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

time = 0
left_outer = 0
cnt_list = []
for a_i in a:
    time_tmp = time + a_i
    if time_tmp <= k:
        time = time_tmp
        left_outer += 1
    else:
        break
cnt_list.append(left_outer)

right_outer = 0
for _ in range(left_outer):
    time -= a[left_outer-1]
    while True:
        if right_outer == len(b):
            break
        time_tmp = time + b[right_outer]
        if time_tmp <= k:
            time = time_tmp
            right_outer += 1
        else:
            break
    cnt_list.append(left_outer + right_outer)
    left_outer -= 1

print(max(cnt_list))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
totalbook = 0
totaltime = 0
for a in range(200000):
    if A[0] <= B[0]:
        tt = A.pop(0)
    else:
        tt = B.pop(0)
    if totaltime + tt <= K:
        totaltime += tt
        totalbook += 1
        A.append(10**9 +1)
        B.append(10**9 +1)
    else:
        break
print(totalbook)

Submission status: Wrong Answer

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

a_i= 0
b_i= 0
f = True

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

for i in range(n+m):
    # print(a_i,b_i,k) 
    if a[a_i] < b[b_i]:
        k -= a[a_i]
        if k < 0:
            print(a_i+b_i)
            exit()
        a_i += 1
        if a_i == n:
            for j in range(m):
                # print(a_i,b_i,k)
                k -= b[b_i]
                if k < 0:
                    print(a_i+b_i)
                    exit()
                b_i += 1
    else:
        k -= b[b_i]
        if k < 0:
            print(a_i+b_i)
            exit()
        b_i += 1
        if b_i == m:
            for j in range(n):
                # print(a_i,b_i,k)
                k -= a[a_i]
                if k < 0:
                    print(a_i+b_i)
                    exit()
                a_i += 1
print(a_i+b_i)

Submission status: Wrong Answer

Solution code:
nmk=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
k=nmk[2]
time=0
cnt=0
while k>=0:
  if len(b)==0:
    k-=a[0]
    _=a.pop(0)
    cnt+=1
  elif len(a)==0:
    k-=b[0]
    _=b.pop(0)
    cnt+=1
  elif a[0]<=b[0]:
    k-=a[0]
    _=a.pop(0)
    cnt+=1
  elif a[0]>b[0]:
    k-=b[0]
    _=b.pop(0)
    cnt+=1
#  print(a,b,k)
  if k<0:
    cnt-=1
  if len(a)==0 and len(b)==0:
    break
print(cnt)

Submission status: Wrong Answer

Solution code:
n,m,k = list(map(int, input().split()))
#print(n,m,k)
a = list(map(int, input().split()))
b = list(map(int, input().split()))
#print(a)
#print(b)
cnt = 0
while k >0 :
  k = k - min(a[0],b[0])
  if k >=0:
    cnt = cnt + 1
  else:
  	break
  #print('k=',k,' cnt=',cnt)
  if a[0] < b[0]:
    del a[0]
  elif a[0] > b[0]:
    del b[0]
  elif a[0] == b[0]:
    del a[0]
  if len(a) == 0:
    while k > 0:
      k = k - b[0]
      cnt = cnt+1
      del b[0]
    break
  if len(b) == 0:
    while k > 0:
      k = k - a[0]
      cnt = cnt+1
      del a[0]
    break
print(cnt)

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


book_num = 0
time = 0
a = 0
b = 0
for i in range(n+m):
  if a_list == []:
    time += b_list[0]
    if time > k:
      break
    b_list.pop(0)
    book_num += 1

  elif b_list == []:
    time += a_list[0]
    if time > k:
      break
    a_list.pop(0)
    book_num += 1


  elif a_list[0] <= b_list[0]:
    time += a_list[0]
    if time > k:
      break
    a_list.pop(0)
    book_num += 1
  elif a_list == []:
    time += b_list[0]
    if time > k:
      break
    b_list.pop(0)
    book_num += 1

  else:
    time += b_list[0]
    if time > k:
      break
    b_list.pop(0)
    book_num += 1

print(book_num)

Submission status: Wrong Answer

Solution code:
from collections import deque

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

    dA = deque([0] + A)
    dB = deque([0] + B)

    sumall = sum(A) + sum(B)
    lenall = len(A) + len(B) 
    Atmp = [0,0]
    Btmp = [0,0]

    Atmp[1] = dA.pop()
    Btmp[1] = dB.pop()

    while sumall > K:
        if Atmp[0] == 0 and dA:
            Atmp[0] = dA.pop()
        if Btmp[0] == 0 and dB:
            Btmp[0] = dB.pop()
        if not dA and not dB:
            print(0)
            return
        if sum(Atmp) >= sum(Btmp):
            sumall -= Atmp[1]
            lenall -= 1
            Atmp[1] = Atmp[0]
            Atmp[0] = 0 
        else:
            sumall -= Btmp[1]
            lenall -= 1
            Btmp[1] = Btmp[0]
            Btmp[0] = 0 
    print(lenall)
                 
solve()

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 = int(stdin.readline().rstrip())
    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)]
    time = 0
    ar = n-1
    br = m-1
    Ar = [0] * (n+1)
    Br = [0] * (m+1)
    ans1 = 0
    for i in range(n):
        Ar[i+1] = Ar[i] + A[i]
    for i in range(m):
        Br[i+1] = Br[i] + B[i]
    while ar >= 0 and br >= 0:
        time = Ar[ar+1] + Br[br+1]
        if time <= k:
            ans1 = ar+br+2
            break
        else:
            if A[ar] < B[br]:
                #Bからのける
                br -= 1
            else:
                ar -= 1

    ans = 0
    time = 0
    a = 0
    b = 0
    while a < n and b < m:
        if A[a] < B[b]:
            if time + A[a] <= k:
                ans += 1
                time += A[a]
                a += 1
            else:
                break
        else:
            if time + B[b] <= k:
                ans += 1
                time += B[b]
                b += 1
            else:
                break
    if a == n:
        #B
        while b < m:
            if time + B[b] <= k:
                ans += 1
                time += B[b]
                b += 1
            else:
                break

    elif b == m:
        #A
        while a < m:
            if time + A[a] <= k:
                ans += 1
                time += A[a]
                a += 1
            else:
                break
    else:
        pass
    print(max(ans1, ans))



if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
N,M,K=map(int,input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
sum_k=0
n=0
if sum_k<K:
    for i in range(max(len(A),len(B))):        
        if len(A)!=0 and len(B)!=0:
            
            if A[0]<B[0]:
                sum_k+=A[0]
                del A[0]
                n+=1
            elif A[0]>=B[0]:
                sum_k+=B[0]
                del B[0]
                n+=1
            
        elif len(A)==0:
            sum_k+=B[0]
            del B[0]
            n+=1
        elif len(B)==0:
            sum_k+=A[0]
            del A[0]
            n+=1
else:
    n-=1

print(n)