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: Accepted

Solution code:
import bisect

n,m,k = map(int,input().split())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

A_sum = [0]*(n+1)
B_sum = [0]*(m+1)

for i in range(n):
    A_sum[i+1] = A_sum[i] + A[i]

for i in range(m):
    B_sum[i+1] = B_sum[i] + B[i]

A_limit = bisect.bisect_right(A_sum,k) - 1
mc = 0
B_i = 0
for i in range(A_limit,-1,-1):
    remain_k = k - A_sum[i]
    while((remain_k-B_sum[B_i])>=0):
        B_i += 1
        if(B_i==(m+1)):
            break
    B_i -= 1
    mc = max(mc,(i+B_i))

print(mc)

Submission status: Accepted

Solution code:
n,m,k=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
AS=[0]
BS=[0]
for i in A:
  if i+AS[-1]<=k:
    AS.append(i+AS[-1])
  else:break
for i in B:
  if i+BS[-1]<=k:
    BS.append(i+BS[-1])
  else:break
r,j=0,len(BS)-1
for i in range(len(AS)):
  while AS[i]+BS[j]>k:
    j-=1
  r=max(r,i+j)
print(r)

Submission status: Accepted

Solution code:
n,m,k=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
AS=[0]
BS=[0]
r=0
for i in A:
  if i+AS[-1]<=k:
    AS.append(i+AS[-1])
  else:
    break
    
for i in B:
  if i+BS[-1]<=k:
    BS.append(i+BS[-1])
  else:
    break
    
j=len(BS)-1
for i in range(len(AS)):
  while AS[i]+BS[j]>k:
    j-=1
  r=max(r,i+j)
print(r)

Submission status: Accepted

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

a, b = [0], [0]
for i in range(n):
  a.append(a[i] + A[i])
for i in range(m):
  b.append(b[i] + B[i])

ans = 0
j = m
for i in range(n + 1):
  if a[i] > k:
    break
  while a[i] + b[j] > k:
      j -= 1
  ans = max(ans, i + j)
    
print(ans)

Submission status: Accepted

Solution code:
def main4():
    N, M, K = map(int, input().split())
    A = [int(a) for a in input().split()]
    B = [int(b) for b in input().split()]
    Bsum = sum(B)
    ans = Asum = 0
    idx_b = len(B) - 1

    for i in range(N + 1):

        if i == 0:
            Asum += 0
        else:
            Asum += A[i - 1]

        while Asum + Bsum > K:
            if idx_b >= 0:
                Bsum -= B[idx_b]
                idx_b -= 1
            else:
                break

        if Asum + Bsum <= K:
            ans = max(ans, i + idx_b + 1)

    print(ans)

if __name__ == "__main__":
    main4()

Submission status: Accepted

Solution code:
def main3():
    N, M, K = map(int, input().split())
    A = [int(a) for a in input().split()]
    B = [int(b) for b in input().split()]
    Bsum = sum(B)
    ans = Asum = 0
    idx_b = len(B) - 1

    for i in range(N + 1):
        if i == 0:
            if Asum + Bsum <= K:
                ans = max(ans, i + idx_b + 1)

            else:
                while Asum + Bsum > K:
                    if idx_b >= 0:
                        Bsum -= B[idx_b]
                        idx_b -= 1
                    else:
                        break
                    
                if Asum + Bsum <= K:
                    ans = max(ans, i + idx_b + 1)

        else:
            Asum += A[i - 1]

            while Asum + Bsum > K:
                if idx_b >= 0:
                    Bsum -= B[idx_b]
                    idx_b -= 1
                else:
                    break
            if Asum + Bsum <= K:
                ans = max(ans, i + idx_b + 1)

    print(ans)

if __name__ == "__main__":
    main3()

Submission status: Accepted

Solution code:
from bisect import bisect_right

def cumsum(a):
    res = [0] * (len(a) + 1)
    for i, v in enumerate(a):
        res[i + 1] = res[i] + v
    return res

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

ans = 0
x = bisect_right(ca, k)
for i in range(x):
    y = bisect_right(cb, k - ca[i])
    ans = max(ans, i + y - 1)

print(ans)

Submission status: Accepted

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]

for i in range(n):
    a.append(a[i] + A[i])
for i in range(m):
    b.append(b[i] + B[i])
    
ans,i = 0,n
for j in range (m + 1):
    if b[j] > k:
        break
    while a[i] > k - b[j]:
        i -= 1
    ans = max(ans,i+j)
print(ans)

Submission status: Accepted

Solution code:
N, M, K = map(int, input().split())
arr_a = list(map(int, input().split()))
arr_b = list(map(int, input().split()))
ans_a =0
ans_b =0
time =0

for i in range(N):
    if time + arr_a[i] > K:
        break
    else:
        ans_a +=1
        time += arr_a[i]
for i in range(M):
    if time + arr_b[i] > K:
        break
    else:
        ans_b +=1
        time += arr_b[i]

ans = ans_a + ans_b
ans_koho = ans_a + ans_b
cnt_b = ans_b

for i in range(ans_a):
    ans_koho -= 1
    time -= arr_a[ans_a-i-1]

    while True:
        if cnt_b == M:
            break
        elif time + arr_b[cnt_b] > K:
            break
        else:
            time += arr_b[cnt_b]
            cnt_b += 1
            ans_koho += 1
    ans = max(ans, ans_koho)

print(ans)

Submission status: Accepted

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

ak=np.cumsum(a,dtype=np.int64)
bk=np.cumsum(b,dtype=np.int64)
ak=ak[ak<=k]
bk=bk[bk<=k]
lak=len(ak)
lbk=len(bk)

an=lak
j=0
for i in range(lak-1,-1,-1):
    while bk[j]+ak[i]<=k:
        an=max(an,i+j+2)
        j+=1
        if j>=lbk:
            j-=1
            break
an=max(an,lbk)

print(an)

Submission status: Accepted

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

i=0
sb=0
while i<m:
    sb+=b[i]
    i+=1
    if sb>k:
        i-=1
        sb-=b[i]
        break

ans=i
j=0
sa=0
while j<n:
    sa+=a[j]
    while sa+sb>k:
        if i>0:
            sb-=b[i-1]
            i-=1
        else:
            print(ans)
            exit()
    j+=1
    ans=max(ans,i+j)

print(ans)

Submission status: Accepted

Solution code:
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
na,nb = [0],[0]
for i in range(n):
  na.append(na[i]+a[i])
for j in range(m):
  nb.append(nb[j]+b[j])
ans = 0
l = m
for i in range(n+1):
  if na[i] > k:
    break
  while nb[l] > k - na[i]:
    l -= 1
  ans = max(ans,i+l)
print(ans)

Submission status: Accepted

Solution code:
from bisect import bisect_left, bisect_right

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for i in range(n-1): a[i+1] = a[i] + a[i+1]
for i in range(m-1): b[i+1] = b[i] + b[i+1]
a = [0] + a; b = [0] + b

c = bisect_right(a, k)-1
ans = 0

for i in range(c+1)[::-1]:
    r = k-a[i]
    j = bisect_right(b, r)-1
    ans = max(ans, i+j)

print(ans)

Submission status: Accepted

Solution code:
from itertools import accumulate
 
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
 
a_accum = [0] + list(accumulate(a))
b_accum = [0] + list(accumulate(b))
 
j = m
for i in range(n+1):
  while k < a_accum[i] + b_accum[j] and j >= 1:
    j -= 1
  if k >= a_accum[i] + b_accum[j] and ans < i + j:
    ans = i + j
print(ans)

Submission status: Accepted

Solution code:
import sys
import itertools as it
from bisect import bisect_left, bisect_right

input = sys.stdin.readline

N, M, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

AS = list(it.accumulate([0]+A))
BS = list(it.accumulate([0]+B))
max_value = 0
for i in range(N+1):
    if AS[i] > K:
        continue
    max_b = K - AS[i]
    ng = bisect_right(BS, max_b)
    ok = ng - 1
    max_value = max(i + ok, max_value)
print(max_value)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-


# def main():
#     n, m, k = map(int, input().split())
#     A = list(map(int, input().split()))
#     B = list(map(int, input().split()))
#     a = A[0]
#     A2 = [a]
#     b = B[0]
#     B2 = [b]
#     for i in range(1, n):
#         a += A[i]
#         A2.append(a)
# 
#     for i in range(1, m):
#         b += B[i]
#         B2.append(b)
#     max = -2
#     for ia, aa in enumerate(A2):
#         for ib, bb in enumerate(B2):
#             if aa + bb > k:
#                 break
#             if ia + ib > max:
# 
#                 max = ia + ib
#     print(max + 2)
# 

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


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

    a, b = [0], [0]
    for i in range(N):
        a.append(a[i] + A[i])
    for i in range(M):
        b.append(b[i] + B[i])

    ans, j = 0, M
    for i in range(N + 1):
        if a[i] > K:
            break
        while b[j] > K - a[i]:
            j -= 1
        ans = max(ans, i + j)
    print(ans)
if __name__ == '__main__':
    answer()

Submission status: Accepted

Solution code:
import sys
import math
import collections
import decimal
import itertools
from collections import deque
from functools import reduce
import heapq
#a = int(input())
n, m, k = map(int, sys.stdin.readline().split())
#s = input()
A = list(map(int, sys.stdin.readline().split()))

B = list(map(int, sys.stdin.readline().split()))

a = [0]
b = [0]
for i in range(n):
    a.append(a[i] + A[i])
    
for i in range(m):
    b.append(b[i] + B[i])

ans = 0
p = m
for i in range(n+1):
    if a[i] > k:
        break

    while ((k - a[i]) < b[p]):
        p -= 1

    ans = max(ans, i+p)

print(ans)

Submission status: Accepted

Solution code:
from itertools import accumulate

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

a_accum = [0] + list(accumulate(a))
b_accum = [0] + list(accumulate(b))

j = m
for i in range(n+1):
  while k < a_accum[i] + b_accum[j] and j >= 1:
    j -= 1
  if k >= a_accum[i] + b_accum[j] and ans < i + j:
    ans = i + j

print(ans)

Submission status: Accepted

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

A = [0] + A
B = [0] + B
for i in range(N):
    A[i + 1] += A[i]
for i in range(M):
    B[i + 1] += B[i]

res, j = 0, M
for i in range(N + 1):
    if A[i] > K:
        break
    while B[j] > K - A[i]:
        j -= 1
    res = max(res, i + j)
print(res)

Submission status: Accepted

Solution code:
from itertools import accumulate
import bisect

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x = 0
a1 = [0] + list(accumulate(a))
b1 = list(accumulate(b))

for i in range(n + 1):
  ren = k - a1[i]
  if ren < 0:
    break
  j = bisect.bisect_right(b1, ren)
  x = max (x, i + j)	
print (x)

Submission status: Accepted

Solution code:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A_sum = [0]
for i in range(N):
    A_sum.append(A[i] + A_sum[i])
B_sum = [0]
for i in range(M):
    B_sum.append(B[i] + B_sum[i])   
    
b_idx = 0
for i in range(1, M+1):
    if B_sum[i] <= K:
        b_idx = i
ans = 0
for i in range(N+1):
    if b_idx > 0:
        while A_sum[i] + B_sum[b_idx] > K:
            b_idx -= 1
            if b_idx < 0:
                b_idx = 0
                break
    if A_sum[i] + B_sum[b_idx] <= K:
        ans = max(ans, i+b_idx)
    else:
        break
print(ans)

Submission status: Accepted

Solution code:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A_sum = [0]
for i in range(N):
    A_sum.append(A[i] + A_sum[i])
B_sum = [0]
for i in range(M):
    B_sum.append(B[i] + B_sum[i])   
    
b_idx = 0
for i in range(1, M+1):
    if B_sum[i] <= K:
        b_idx = i
ans = 0
for i in range(N+1):
    if b_idx > 0:
        while A_sum[i] + B_sum[b_idx] > K:
            b_idx -= 1
            if b_idx < 0:
                b_idx = 0
                break
    if A_sum[i] + B_sum[b_idx] <= K:
        ans = max(ans, i+b_idx)
print(ans)

Submission status: Accepted

Solution code:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A_sum = [0]
for i in range(N):
    A_sum.append(A[i] + A_sum[i])
B_sum = [0]
for i in range(M):
    B_sum.append(B[i] + B_sum[i])    
import bisect
ans = 0
for i in range(N+1):
    a = A_sum[i]
    if K-a >=0:
        b_idx = bisect.bisect(B_sum, K-a) - 1
        if b_idx  < 0:
            b_idx = 0
        ans = max(ans, i+b_idx)
print(ans)

Submission status: Accepted

Solution code:
def A(x):
  return x + x**2 + x**3


def B(s, t):
  ans = 0
  for i in range(len(s)):
    if s[i] != t[i]:
      ans += 1
  return ans


def C(n, m, k, a, b):

  def _get_acc(x):
    acc = [0]
    for idx in range(len(x)):
      acc.append(x[idx] + acc[idx])
    return acc

  acc_a = _get_acc(a)
  acc_b = _get_acc(b)

  pa = 0
  pb = 0

  while pa <= n and acc_a[pa] <= k:
    pa += 1
  pa -= 1

  max_num = 0
  while True:
    if pa < 0 or pb > m:
      break
    if acc_a[pa] + acc_b[pb] <= k:
      if max_num < pa + pb:
        max_num = pa + pb
      pb += 1
    else:
      pa -= 1

  return max_num


def main():
  n, m, k = map(int, input().split())
  a = list(map(int, input().split()))
  b = list(map(int, input().split()))
  print(C(n, m, k, a, b))


if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
import bisect

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

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

A_sum = A.copy()
B_sum = B.copy()

for i in range(1, N):
    A_sum[i] = A_sum[i - 1] + A[i]

A_sum = [0] + A_sum

for i in range(1, M):
    B_sum[i] = B_sum[i - 1] + B[i]


max_ = 0
for i, n in enumerate(A_sum):
    if n > K:
        continue

    target = K - n
    v = bisect.bisect_left(B_sum, target)

    if v != M and B_sum[v] == target:
        v += 1

    max_ = max(max_, i + v)

print(max_)

Submission status: Accepted

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

sumT = 0
cnt = 0
cntL = []
cntMax = 0
AMax = 0
BMax = 0

if (A[0]>K and B[0]>K):
    print(0)
    exit()

for i in range(len(A)):
    sumT += A[i]
    cnt += 1
    if (sumT > K):
        sumT -= A[i]
        cnt -= 1
        break

AMax = cnt-1
cntL.append(cnt)


for i in range(len(B)):
    sumT += B[i]
    cnt += 1
    if (sumT<=K):
        cntL.append(cnt)
    while (sumT > K):
        if (AMax<0):
            break
        sumT -= A[AMax]
        AMax -= 1
        cnt -= 1

print(max(cntL))

Submission status: Accepted

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

a,b = [0],[0]
for i in range(N):
  a.append(a[i]+A[i])
for i in range(M):
  b.append(b[i]+B[i])

ans,j = 0,M
for i in range(N+1):
  if a[i] > K:
    break
  while b[j] > K - a[i]:
    j -= 1
  ans = max(ans,i+j)
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
import math
import collections
import bisect
from difflib import SequenceMatcher


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

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

    cumsumA = np.cumsum(A)
    p = bisect.bisect_left(cumsumA, K + 0.1)
    time = cumsumA[p - 1]
    tmp = p
    ans = tmp

    cntA = 0
    import numpy as np


import math
import collections
import bisect
from difflib import SequenceMatcher


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

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

    cumsumA = np.cumsum(A)
    a = bisect.bisect_left(cumsumA, K + 0.1) - 1
    time = cumsumA[a]
    tmp = a + 1
    ans = tmp

    b = 0
    while(b < len(B)):
        #print(a, b, ans)
        if time + B[b] <= K:
            time += B[b]
            tmp += 1
            b += 1
            if tmp > ans:
                ans = tmp
        else:
            if a < 0:
                break
            time -= A[a]
            tmp += -1
            a += -1

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
suma=[0]*(n+1)
suma[1]=a[0]
acnt=1
for i in range(2,n+1):
  if suma[i-1] > k:
    break
  suma[i] = suma[i-1]+a[i-1]
  acnt+= 1
#acnt:sumaが入っている範囲
btt=0
btl=0
res=0
ans=0
for i in reversed(range(acnt+1)):
  res=suma[i]+btt
  if res > k:
    continue
  for j in range(btl,m):
    if res+b[j] <= k:
      res += b[j]
      btt += b[j]
      btl += 1
    else:
      break
  ans = max(ans, i+btl)
print(ans)

Submission status: Accepted

Solution code:
#map関数は、配列のすべての要素にアクセスすることが可能です。
#空白文字にはスペースや改行\n, タブ\tが含まれ、連続する空白文字はまとめて処理される。
N,M,K=map(int,input().split())

A=[int(x) for x in input().split()]
B=[int(x) for x in input().split()]

a=[0]
b=[0]

tmp_a=0
for i in A:
    tmp_a+=i
    a.append(tmp_a)
    
tmp_b=0
for i in B:
    tmp_b+=i
    b.append(tmp_b)
    


ans,j=0,M
for i in range(N+1):
    if a[i]>K:
        break
    while(1):
        if b[j]<=(K-a[i]):
            break
        j-=1
    ans=max(ans,i+j)
    
print(ans)

Submission status: Accepted

Solution code:
from itertools import accumulate

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

a_acc = [0] + list(accumulate(a))
b_acc = [0] + list((accumulate(b)))

ans = 0
bn = m

for an in range(n + 1):
    rem = k - a_acc[an]
    if rem < 0:
        break

    # rem >= 0 かつ、b_acc[0] = 0なので、bnはどんなに減っても0で必ず止まります。マイナスになってバグることはありません
    while b_acc[bn] > rem:
        bn -= 1
    ans = max(ans, an + bn)

print(ans)

Submission status: Accepted

Solution code:
from itertools import accumulate

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

a_acc = [0] + list(accumulate(a))  # aを0冊読む=1冊も読まない場合があるので
b_acc = [0] + list((accumulate(b)))  # 今度は[0]が必要です

ans = 0
for an in range(n + 1):
    rem = k - a_acc[an]
    if rem < 0:
        break

    # 最初は 0 <= x < m + 1 の範囲で、この範囲を狭めていきます
    ok = 0
    ng = m + 1   
    # ng = ok + 1のとき、ok <= x < ng は ok <= x < ok + 1で、x = okに確定します
    while abs(ng - ok) > 1:
        mid = (ok + ng) // 2
        # bをmid冊読めるか？
        if b_acc[mid] <= rem:
        # 読めるならok
            ok = mid
        else:
        # 読めないならng
            ng = mid

    bn = ok
    ans = max(ans, an + bn)

print(ans)

Submission status: Accepted

Solution code:
from itertools import accumulate
import bisect

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

a_acc = [0] + list(accumulate(a))  # aを0冊読む=1冊も読まない場合があるので、[0]を先頭に追加します
b_acc = list((accumulate(b)))  # bisect_rightでは、x以下の要素がいくつあるか？を求めるので、こちらに0は入れません

ans = 0
for an in range(n + 1):
    rem = k - a_acc[an]
    if rem < 0:
        # aをこれ以上読めません
        break

    bn = bisect.bisect_right(b_acc, rem)
    ans = max(ans, an + bn)

print(ans)

Submission status: Accepted

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

t = sum(B)

# しゃくとり法
res = 0
j = m
for i in range(n + 1):
    while j > 0 and t > k:
        j -= 1
        t -= B[j]
    if t > k:
        break
    res = max(res, i + j)
    if i == n: break
    t += A[i]

print(res)

Submission status: Accepted

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

a, b = [0], [0]
for i in range(N):
  a.append(a[i] + A[i])
for i in range(M):
  b.append(b[i] + B[i])
ans, j = 0, M
for i in range(N + 1):
  if a[i] > K:
    break
  while b[j] > K - a[i]:
    j -= 1
  ans = max(ans, i + j)

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
N,M,K = map(int, input().split())

A = np.array([0] + list(map(int, input().split())))
B = np.array([0] + list(map(int, input().split())))

CA = np.cumsum(A)
CB = np.cumsum(B)

ans = 0
for i in range(N+1):
  if CA[i] > K:
    break
  j = np.searchsorted(CB, K-CA[i], side='right') - 1
  ans = max(ans, i+j)
  #print(ans,i,j)
  
#print(CA)
#print(CB)
print(ans)

Submission status: Accepted

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

Mcan = 0
for i in range(M):
    if(Ktmp + B[i] > K):
        break
    Ktmp += B[i]
    Mcan += 1

ans = 0

while(1):
    while(1):
        if(Mcan >= M):
            break
        if(Ktmp + B[Mcan] > K):
            break
        Ktmp += B[Mcan]
        Mcan += 1
    anstmp = Ncan + Mcan
    ans = max(ans, anstmp)

    Ncan -= 1
    if(Ncan == -1):
        break
    Ktmp -= A[Ncan]

print(ans)

Submission status: Accepted

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

a = [0] + a
b = [0] + b

for i in range(1, n+1):
    a[i] += a[i-1]

for i in range(1, m+1):
    b[i] += b[i-1]

ans = 0

j = m
for i in range(n+1):
    while j > 0 and b[j] + a[i] > k:
        j -= 1
    if a[i] + b[j] > k:
        break

    ans = max(ans, i + j)


print(ans)

Submission status: Accepted

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

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

a, b = [0], [0]

for i in range(N):
    a.append(a[i] + A[i])
for i in range(M):
    b.append(b[i] + B[i])

ans,j = 0, M
for i in range(N + 1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j -= 1
    ans = max(ans, i + j)
print(ans)

Submission status: Accepted

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

a, b = [0], [0]

for i in range(len(A)):
    a.append(a[i] + A[i])
for i in range(len(B)):
    b.append(b[i] + B[i])

ans, j = 0, M
for i in range(N+1):
    if a[i] > K:
        break
    while a[i] + b[j] > K:
        j -= 1
    ans = max(ans, i+j)
    
print(ans)

Submission status: Accepted

Solution code:
n,m,k = map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
 
asum=[0]
bsum=[0]
for i in range(n):
    asum.append(asum[i]+a[i]) #机aからi冊読んだ時間の合計
for i in range(m):
    bsum.append(bsum[i]+b[i]) #机bからi冊読んだ時間の合計
 
t=0
for i in range(n+1):
    if asum[i]>k: #机aからi冊読めるか検討
        break
    now=k-asum[i] #机aからi冊読んだ後の残り時間
    while bsum[m]>now:
        m-=1 #机bのm冊の本で何冊削るか検討
    if t<i+m:
        t=i+m #iが増えてもmが変わらないとき
        
print(t)

Submission status: Accepted

Solution code:
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
count = 0
bi = 0
for j in range(M):
    if count + B[j] > K:
        break
    count += B[j]
    bi += 1
a=0
ai = 0
p = bi
for i in range(N):
    #ep('s1:',count,ai,bi)
    if a + A[i] > K:
        break;
    a += A[i]
    count += A[i]
    ai+=1
    #ep('s2:',count,ai,M)
    
    while count>K:
        count-=B[bi-1]
        bi-=1
    #ep('s3:',count,ai,M)
    if count <= K:
        p=max(p,ai+bi)
    #ep('s4',count,p,ai,M)
print(p)

Submission status: Accepted

Solution code:
import bisect
N,M,K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
for i in range(1,N):
    A[i]+=A[i-1]

index = bisect.bisect(A,K)
for i in range(M):
    K-=B[i]
    if K>=0:
        a=bisect.bisect(A,K)
        if a+i+1>=index:
            index=a+i+1
print(index)

Submission status: Accepted

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

a,b = [0],[0]
for i in range(N):
    a.append(a[i]+A[i])
for j in range(M):
    b.append(b[j]+B[j])

ans = 0
j = M
for i in range(N+1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j -= 1
    ans = max(ans,i+j)
print(ans)

Submission status: Accepted

Solution code:
import bisect
N,M,K = map(int, input().split())
A= list(map(int, input().split()))
B = list(map(int, input().split()))
for i in range(1,len(A)):
    A[i]+=A[i-1]
for i in range(1,len(B)):
    B[i]+=B[i-1]
honn=a=bisect.bisect(B,K)
for i in range(len(A)):
    s=K-A[i]
    if s>=0:
        a=bisect.bisect(B,s)
        if i+1+a>honn:
            honn=i+1+a
print(honn)

Submission status: Accepted

Solution code:
n_book_a, n_book_b, limit_time = map(int, input().split(" "))
read_time_a = [int(i) for i in input().split(" ")]
read_time_b = [int(i) for i in input().split(" ")]

read_sum_time_a = [0]  # 1冊も読まないパターン
for i in range(n_book_a):
    read_sum_time_a.append(read_sum_time_a[i] + read_time_a[i])
    
read_sum_time_b = [0]  # 1冊も読まないパターン
for i in range(n_book_b):
    read_sum_time_b.append(read_sum_time_b[i] + read_time_b[i])

# print(read_sum_time_a)
# print(read_sum_time_b)

ans = 0
i_b = n_book_b  # 数が大きい方から一通り確認していく
for i_a, time_a in enumerate(read_sum_time_a):
    # print(time_a)
    # read_sum_time_aがlimit_time以下の場合についてのみ調べる
    if time_a > limit_time:
        break
    else:     
        while read_sum_time_b[i_b] + time_a > limit_time:
            i_b += -1
            # i_a + i_bがansより大きいと気に更新をサラッと書くとこうなる(i_a, i_bはA, Bの冊数)
        ans = max(ans, i_a + i_b)
        # print(f"ans: {ans}")
    
print(ans)

Submission status: Accepted

Solution code:
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
Asum = [0]*(N+1)
Bsum = [0]*(M+1)
Asum[0] = 0
Bsum[0] = 0
for i in range(N):
    Asum[i+1] = Asum[i]+A[i]
for i in range(M):
    Bsum[i+1] = Bsum[i]+B[i]
    
bestbooks = 0
upup = M+1
for i in range(N+1):
    lasttime = K - Asum[i]
    if lasttime < 0:
        break
    for j in reversed(range(0,upup)):
        #print(i,j,upup,lasttime,bestbooks)
        if Bsum[j] <= lasttime and i+j>bestbooks:
            bestbooks = i+j
           
        if Bsum[j] <= lasttime:
            upup = j+1
            break
            
print(bestbooks)

Submission status: Accepted

Solution code:
import itertools
import bisect
N, M ,K = map(int,input().split())
al = list(map(int,input().split()))
bl = list(map(int,input().split()))

accum_al = list(itertools.accumulate(al))
accum_bl = list(itertools.accumulate(bl))
accum_al.insert(0,0)
accum_bl.insert(0,0)
# print(accum_al)
# print(accum_bl)

ans = 0
index = 0
for i in range(N+1):
    nokori = K - accum_al[i]
    if nokori < 0:
        continue
    else:
        index = bisect.bisect_right(accum_bl,nokori)-1
    tmp = i + index
    #print(i,index,tmp)
    if tmp > ans:
        ans = tmp
print(ans)

Submission status: Accepted

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

arui = [0]
brui = [0]
for i in range(n):
    arui.append(arui[-1]+a[i])
for i in range(m):
    brui.append(brui[-1]+b[i])

left = 0
right = n+m+1
while left+1 < right:
    mid = (left + right) // 2
    if mid <= n:
        aidx = mid
        bidx = 0
    else:
        aidx = n
        bidx = mid - n
    ok = 0
    while aidx >= 0 and bidx <= m:
        time = arui[aidx] + brui[bidx]
        if time <= k:
            ok = 1
            break
        aidx -= 1
        bidx += 1
    if ok:
        left = mid
    else:
        right = mid

print(left)

Submission status: Accepted

Solution code:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
#print(a)
asum=[0]
bsum=[0]
cnt=0
for i in range(n):
    cnt+=a[i]
    asum.append(cnt)
#    if cnt>k:
#        amx=i
#        break
#    amx=i
#print("amx=",amx)

cnt=0
for i in range(m):
    cnt+=b[i]
    bsum.append(cnt)
#    if cnt>k:
#        bmx=i
#        break
#    bmx=i
#print("bmx=",bmx)

ans=0
j=m
for i in range(n+1):
    c=k-asum[i]
#    print("i=",i)
#    print("c=",c)
    if c<0:
        continue
    while c<bsum[j] and j>0:
        j-=1
    ans=max(ans,i+j)
#    print("ans=",ans)
print(ans)

Submission status: Accepted

Solution code:

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

t=0
i=0
la=[]
for x in a :
    if t+x>k :
        break
    t+=x
    i+=1
    la.append(x)
# while i<n :
#     if t+a[i]>k :
#         break
#     t+=a[i]
#     i+=1

# j=0
# while j<m :
#     if t+b[j]>k :
#         break
#     t+=b[j]
#     j+=1
j=0
for x in b :
    # print("mk1 x=",x)
    if t+x>k :
        break
    t+=x
    j+=1

ans=i+j
while i>0 :
    i-=1
    t-=la[-1]
    la.pop(-1)
    if t+x>k :
        continue
    else:
        t+=x
        j+=1
    for x in b :
        # print("mk2 x=",x)
        if t+x>k :
            break
        t+=x
        j+=1
    # while j<m and t+b[j]<=k :
    #     t+=b[j]
    #     j+=1
    ans=max(ans,i+j)

print(ans)

Submission status: Accepted

Solution code:

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

t=0
i=0
while i<n :
    if t+a[i]>k :
        break
    t+=a[i]
    i+=1

# j=0
# while j<m :
#     if t+b[j]>k :
#         break
#     t+=b[j]
#     j+=1
j=0
for x in b :
    # print("mk1 x=",x)
    if t+x>k :
        break
    t+=x
    j+=1

ans=i+j
while i>0 :
    i-=1
    t-=a[i]
    if t+x>k :
        continue
    else:
        t+=x
        j+=1
    for x in b :
        # print("mk2 x=",x)
        if t+x>k :
            break
        t+=x
        j+=1
    # while j<m and t+b[j]<=k :
    #     t+=b[j]
    #     j+=1
    ans=max(ans,i+j)

print(ans)