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:
from bisect import bisect_right
n, m, k = map(int, input().split())
li_a = list(map(int, input().split()))
li_b = list(map(int, input().split()))
sa = [0] * (len(li_a)+1)
sb = [0] * (len(li_b)+1)
for i in range(n):
    sa[i+1] = sa[i] + li_a[i]
for i in range(m):
    sb[i+1] = sb[i] + li_b[i]
ans = 0

for i in range(n+1):
    tmp = k
    tmp -= sa[i]
    if tmp >= 0:
        bi = bisect_right(sb, tmp)
        ans = max(ans, i+bi-1)
print(ans)

Submission status: Accepted

Solution code:
import collections
n,m,k = map(int, raw_input().split(' '))
ais = map(int,raw_input().split(' '))
bis = map(int,raw_input().split(' '))
cumul = 0
pais = [0]
for ai in ais:
	cumul +=ai
	pais.append(cumul)

cumul = 0
pbis = [0]
for ai in bis:
	cumul +=ai
	pbis.append(cumul)
	


q = 0
for j,bi in enumerate(pbis):

	if k >= bi:
		j
		qq = k - bi
		lo,hi = 0, len(pais)-1
		while(lo < hi):
			med = (lo + hi + 1) >> 1
			if pais[med] <= qq:
				lo = med
			else:
				hi = med -1
		
		ans = j + lo
		q = max(ans, q)
print q

Submission status: Accepted

Solution code:
import bisect
# listのpopを使う
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
# 純粋に小さい方を読んでいく
ans = 0
# 1番上しか読めない
# while K >= A[0] or K >= B[0]:
#     if A[0]
cumulative_sum_of_A = [0]
cumulative_sum_of_B = [0]
for i in range(N):
    cumulative_sum_of_A.append(cumulative_sum_of_A[-1]+A[i])

for i in range(M):
    cumulative_sum_of_B.append(cumulative_sum_of_B[-1]+B[i])

# print(cumulative_sum_of_A)
# print(cumulative_sum_of_B)

ans = 0
for i in range(N+1):
    # print(ans)
    if cumulative_sum_of_A[i] > K:  # それ以上Aを読めないならアウト
        break
    tmp = i  # A側の本をi冊読む  # 0の場合もあり
    remaining = K - cumulative_sum_of_A[i]  # 残り時間
    upper_bound = bisect.bisect_right(cumulative_sum_of_B, remaining)-1
    tmp += upper_bound
    ans = max(tmp, ans)
print(ans)

Submission status: Accepted

Solution code:
def find(A,B,K):

    pre_A = []
    pre_B = []
    temp_A = 0
    temp_B = 0
    
    for x in A:
        temp_A += x
        pre_A += [temp_A]
    for x in B:
        temp_B += x
        pre_B += [temp_B]
    
    
    
    def okay(num,K):
        if num == 0:
            return True
        
        if len(A) + len(B) <num:
            return False
        
        total = 10**9
        for i in range(0,num+1):
            if num-1-i>=len(A):
                continue
            if i-1>=len(B):
                continue
            if i == 0:
                total = pre_A[num-1]
            elif i == num:
                total = pre_B[num-1]
            else:
                total = pre_A[num-1-i] + pre_B[i-1]
            if total<=K:
                return True
        return False
    
    
    left = 0
    right = len(A) + len(B) + 1
    while right - left>1:
        mid = (right+left)//2
        if okay(mid,K):
            left = mid
        else:
            right = mid

        
    return left
        
        
N,M,K = list(map(int,input().strip().split()))
A = list(map(int,input().strip().split()))
B = list(map(int,input().strip().split()))
print(find(A,B,K))

Submission status: Accepted

Solution code:

def main(N, M, K, A, B):
    ans = 0
    time = sum(B)
    j = M
    Loop = True
    for i in range(N+1):
        while True:
            if time > K:
                if j == 0:
                    Loop = False
                    break
                j -= 1
                time -= B[j]
            else:
                ans = max(ans, j+i)
                break
        if Loop == False:
            break
        if i == N:
            break
        time += A[i]
    return ans


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

Submission status: Accepted

Solution code:
from collections import deque
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=deque(map(int,input().split()))
a=deque()
t=0
for i in range(N):
    if t+A[i]<=K:
        a.append(A[i])
        t+=A[i]
    else:
        break
m=K-t
ans=len(a)
while B and B[0]<=m:
    m-=B[0]
    B.popleft()
    ans+=1
if not B:
    print(ans)
    exit()
c=ans
while a:
    m+=a.pop()
    c-=1
    while B and B[0]<=m:
        m-=B[0]
        B.popleft()
        c+=1
    ans=max(ans,c)
print(ans)

Submission status: Accepted

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

a = numpy.cumsum(A)
b = numpy.cumsum(B)
ans = 0
for i in range(n):
    if a[i] <= k:
        c = bisect.bisect(b, k-a[i])
        ans = max(ans, i+c+1)
for i in range(m):
    if b[i] <= k:
        c = bisect.bisect(a, k-b[i])
        ans = max(ans, i+c+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()))
import itertools
x = list(itertools.accumulate(a))
y = list(itertools.accumulate(b))

import bisect
ans = bisect.bisect(y,k)
for i in range(n):
    if k-x[i]>=0:
        buf = i + 1 + bisect.bisect(y,k-x[i])
        ans = max(ans,buf)
    else:
        break
print(ans)

Submission status: Accepted

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

S = 0
a_idx = 0
for a in A:
    if S + a > K:
        break
    S += a
    a_idx += 1

b_idx = 0
for b in B:
    if S + b > K:
        break
    S += b
    b_idx += 1

ans = a_idx + b_idx
while a_idx > 0:
    a_idx -= 1
    S -= A[a_idx]
    while b_idx < M and S + B[b_idx] <= K:
        S += B[b_idx]
        b_idx += 1
    ans = max(ans, a_idx + b_idx)
print(ans)

Submission status: Accepted

Solution code:
import bisect


_, _, k = map(int, input().split())
*A, = map(int, input().split())
*B, = map(int, input().split())
A.insert(0, 0)
B.insert(0, 0)

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

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


res = 0
for i in range(len(A)):
    if k < A[i]:
        break

    j = bisect.bisect_left(B, k - A[i])
    if j == len(B) or B[j] > k - A[i]:
        j -= 1


    cnt = i + j
    res = max(res, cnt)
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()))

rui_a=[]
rui_b=[]

sm=0
for tmp in b:
    rui_b.append(sm)
    sm+=tmp
rui_b.append(sm)

sm=0
for tmp in a:
    rui_a.append(sm)
    sm+=tmp
rui_a.append(sm)


import bisect

ans=0
for a_num in range(n+1):
    nokori=k-rui_a[a_num]
    if nokori < 0:
        continue
    b_num = bisect.bisect_right(rui_b,nokori) -1

    ans=max(ans,a_num+b_num)
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()))
asu=[0]*(n+1)
bsu=[0]*(m+1)
for i in range(n):
    asu[i+1]=asu[i]+a[i]
for i in range(m):
    bsu[i+1]=bsu[i]+b[i]
ans=0
cnt=0
for i in range(n+1):
    lim=k-asu[i]
    if lim<0:break
    ans=max(ans,bisect.bisect_right(bsu,lim)+i-1)
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()))
ans = 0
A = [0]
B = [0]
for i in range(n):
    A.append(A[-1]+a[i])
for i in range(m):
    B.append(B[-1]+b[i])

for i in range(n+1):
    if A[i] <= k:
        ans = max(i+bisect.bisect(B,k-A[i])-1,ans)
    else:
        break

for i in range(m+1):
    if B[i] <= k:
        ans = max(i+bisect.bisect(A,k-B[i])-1,ans)
    else:
        break
print(ans)

Submission status: Accepted

Solution code:
import bisect

N, M, K = map(int, input().split())
Alist = [0] + list(map(int, input().split()))
Blist = list(map(int, input().split()))

B = [Blist[0]]
for b in Blist[1:]:
    B.append(b + B[-1])


sums = 0
ans = 0
for idx, a in enumerate(Alist):
    sums += a
    if sums > K:
        break
    k = K - sums
    tmp = bisect.bisect_right(B, k)
    ans = max(ans, idx + tmp)

print(ans)

Submission status: Accepted

Solution code:
#

import sys
from bisect import bisect
input=sys.stdin.readline

def main():
    N,M,K=map(int,input().split())
    A=list(map(int,input().split()))
    B=list(map(int,input().split()))
    Ar=[0]*(N+1)
    Br=[0]*(M+1)
    for i in range(N):
        Ar[i+1]=Ar[i]+A[i]
    for i in range(M):
        Br[i+1]=Br[i]+B[i]
        
    maxb=0
    for i in range(N+1):
        if maxb<i+bisect(Br,K-Ar[i])-1 and K>=Ar[i]:
            maxb=i+bisect(Br,K-Ar[i])-1
    print(maxb)
        
            
    
    
if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n,m,k = na()
a = na()
b = na()
aa = [0]
bb = [0]

for i in a:
    aa.append(aa[-1]+i)
for i in b:
    bb.append(bb[-1]+i)

import bisect
ans = 0
for i in range(n+1):
    if aa[i] > k:
        break
    kk = k-aa[i]
    ans = max(ans, i+bisect.bisect_right(bb,kk)-1)

print(ans)

Submission status: Accepted

Solution code:
import sys
import math
from collections import deque
import heapq
import itertools
from decimal import Decimal
import bisect
from operator import itemgetter
MAX_INT = int(10e18)
MIN_INT = -MAX_INT
mod = 1000000000+7
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N,M,K = IL()
a = IL()
b = IL()

ruia = [0]
for i in range(N):
  ruia.append(ruia[-1] + a[i])

ruib = [0]
for i in range(M):
  ruib.append(ruib[-1] + b[i])

r = N
l = 0
ans = 0
for l in range(M+1):
  while ruia[r] + ruib[l] > K:
    r -= 1
    if r == -1:
      break  
  cnt = r+l
  ans = max(ans, cnt)
  if r == -1:
    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()))

sumtime = 0

bi = 0
while bi < m and sumtime + b[bi]<=k:
    sumtime += b[bi]
    bi += 1
    
ans = bi
for ai in range(n):
    sumtime += a[ai]
    while bi>=1 and sumtime>k:
        bi -= 1
        sumtime -= b[bi]
    
    if sumtime<=k:
        ans = max(ans, ai+bi+1)
    
    
print(ans)

Submission status: Accepted

Solution code:
from bisect import bisect_right

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

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

Submission status: Accepted

Solution code:
import bisect
from itertools import accumulate

n, m, k = map(int, input().split())
aaa = list(map(int, input().split()))
bbb = list(map(int, input().split()))

aaa = [0] + list(accumulate(aaa))
bbb = [0] + list(accumulate(bbb))


ans = 0
for i in range(len(aaa)):
    rest = k - aaa[i]
    if rest >= 0:
        div = bisect.bisect_right(bbb, rest) - 1
        ans = max(ans, i + div)

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()))
cnt = 0
T = 0
maxi=N
cnt = N
for i in range(N):
    T += A[i]
    if T>K:
        maxi = i
        cnt = i
        T = T-A[i]
        break

out = cnt
Life=K-T
Bt = 0
while (Bt<=M-1) and (maxi>=0):
    Bcnt=0
    if Life-B[Bt]>=0:
        Life += -1*B[Bt]
        Bt += 1
        Bcnt+=1
    else:
        Life += A[maxi-1]
        maxi += -1
        Bcnt += -1
    cnt = cnt+Bcnt
    out = max(out,cnt)
print(out)

Submission status: Accepted

Solution code:
import bisect
import copy
import heapq
import sys
import itertools
import math
import queue
from functools import lru_cache
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7 

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


class V:
    def __init__(self, f, v=None):
        self.f = f
        self.v = v
 
    def __str__(self):
        return str(self.v)
 
    def ud(self, n):
        if n is None:
            return

        if self.v is None:
            self.v = n
            return
        self.v = self.f(self.v, n) 


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

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

    SB = [0] * (M + 1)
    for i in range(M):
        SB[i + 1] = SB[i] + B[i]

    res = V(max, 0)
    for i in range(N):
        j = bisect.bisect_right(SB, K) - 1
        res.ud(j + i)
        K -= A[i]
        if K < 0:
            break
    else:
        j = bisect.bisect_right(SB, K) - 1
        res.ud(j + N)
    
    print(res)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

    ans = 0
    time = 0

    for i in range(N):
        ans += 1
        time += A[i]
        if time > K:
            ans -= 1
            time -= A[i]
            break
    a_bottom = ans - 1
    
    cnt = ans
    b_bottom = 0
    while b_bottom < M:
        if time + B[b_bottom] <= K:
            time += B[b_bottom]
            cnt += 1
            ans = max(cnt, ans)
            b_bottom += 1
        else:
            if a_bottom == -1:
                break
            time -= A[a_bottom]
            a_bottom -= 1
            cnt -= 1
    
    print(ans)

if __name__ == '__main__':
    solve()

Submission status: Accepted

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

def binary_search(l,r,func):
    if func(l):return l-1
    if not func(r):return r
    while l+1<r:
        i = (l+r)//2
        if func(i):
            r = i
        else:
            l = i
    return l


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]

def g(i,t):
    return B[i]>t
ans = 0

for i,a in enumerate(A):
    T = K-a
    if T<0 : break
    gt = lambda x:g(x,T)
    tmp = binary_search(0,M,gt)
    ans = max(ans,tmp+i)
print(ans)

Submission status: Accepted

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

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

ret = 0
a = N - 1
b = 0
while b < M :
  while a >= 0 and A[a] + B[b] > K :
    a -= 1
  if a >= 0 and A[a] + B[b] <= K :
    ret = max(ret, a + b)
  b += 1
  
print(ret)

Submission status: Accepted

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
	return list(map(int,input().split()))
def m(): #複数文字
	return map(int,input().split())
def onem(): #Nとかの取得
	return int(input())
def s(x): #圧縮
	a = []
	if len(x) == 0:
		return []
	aa = x[0]
	su = 1
	for i in range(len(x)-1):
		if aa != x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a
def jo(x): #listをスペースごとに分ける
	return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
	return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
	ll = 0
	rr = r
	while True:
		mid = (ll+rr)//2

	if rr == mid:
		return ll
	if (ここに評価入れる):
		rr = mid
	else:
		ll = mid+1
"""

a,b,t = m()

aa = l()

bb = l()

co = 0

ccc = 0

ans = 0

no = 0

aaa = [0 for i in range(a+1)]

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

for i in range(b+1):
	if i != 0:
		no += bb[i-1]
	if t-no >= 0:
		popopo = bs.bisect_left(aaa,t-no)
		if popopo <= a and aaa[popopo] == t-no:
			popopo += 1
		
		ans = max(ans,i + popopo-1)

print(ans)

Submission status: Accepted

Solution code:
# ABC172c


def main():
    import sys
    import bisect
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    # 再帰関数を使わない限りPypyで出すこと

    def dump(*args):
        sys.stderr.write(str(args))

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

    def cum(array):  # result[i]=i番目まで（1-indexed）の累積和
        result = [0]
        for i in range(len(array)):
            result.append(array[i]+result[i])
        return result

    bc = cum(b)
    ac = cum(a)
    ans = 0
    for i in range(n + 1):
        if ac[i] <= k:
            #print(i, bisect.bisect_left(bc, k - ac[i])-1)
            ans = max(ans, i + bisect.bisect_right(bc, k - ac[i])-1)
    print(ans)


if __name__ == '__main__':
    main()

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

ans = 0
m = 0
for i in A:
  m += i
  if m > K:
    break
  ans += 1

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

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

if ans == 0:
  t = 0
else:
  t = C[ans - 1]

k = ans
n = ans
for i in range(M):
  m = D[i]
  if m > K: break
  while m + t > K:
    n -= 1
    if n <= 0:
      t = 0
      break
    t = C[n - 1]
  ans = max(ans, i + 1 + n)

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter, defaultdict
# for use in beginner level contests where speed is key
import bisect

_,_,k = list(map(int,input().split()))
aa = list(map(int,input().split()))
bb = list(map(int,input().split()))

cs = 0
cc = [0]
for a in aa:
    cs += a
    # print(cs)
    cc.append(cs)

cs = 0
dd = [0]
for b in bb:
    cs += b
    # print(cs)
    dd.append(cs)

# print(cc)
# print(dd)

res = 0
for i,d in enumerate(dd):
    if k-d < 0:
        continue
    j = bisect.bisect_right(cc, k-d)-1
    # if dd[i] + cc[j] > k:
    #     continue
    # print(i,j,k-d,dd[i],cc[j])
    res = max(res, i+j)
print(res)

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

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

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

ans = 0
r = m

for i in range(n+1):
    while 0 < r and k < a[i] + b[r]:
        r -= 1

    if a[i] + b[r] <= k:
        ans = max(ans, i + r)

print(ans)

Submission status: Accepted

Solution code:
import math
import pprint
import fractions
import collections
import itertools
from decimal import *
from collections import deque
from bisect import *
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
a=deque()
b=deque()
mula=[0]*(N+1)
mulb=[0]*(M+1)
for i in range(N):
    mula[i+1]=mula[i]+A[i]
for i in range(M):
    mulb[i+1]=mulb[i]+B[i]
#print(mula,mulb)
ans=0
for i in range(N+1):
    cnt = 0
    timeb=K-mula[i]
    cnt=cnt+i
    #print(timeb)
    #print(bisect(mulb,timeb))
    if bisect(mulb,timeb)-1>=0:
        cnt=cnt+bisect(mulb,timeb)-1
        ans=max(ans,cnt)
print(ans)

Submission status: Accepted

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

finalres = 0
res1 = 0
r1 = 0
t = 0
while r1 < len(dat1):
    if t + dat1[r1] <= k:
        res1 += 1
        t += dat1[r1]
        r1 += 1
    else:
        break

#print("r1", r1, t)
finalres = res1
res2 = 0
r2 = 0
while r2 < len(dat2):
    if t + dat2[r2] <= k:
        res2 += 1
        t += dat2[r2]

        r2 += 1
        finalres = max(finalres, res1+res2)
    else:
        if r1 == 0:
            break
        r1 -= 1
        res1 -= 1
        t -= dat1[r1]

print(finalres)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import itertools
import bisect

N, M, K = map(int, input().split())
A = [0] + list(map(int, input().split()))
B = [0] + list(map(int, input().split()))

cumA = list(itertools.accumulate(A))
cumB = list(itertools.accumulate(B))
#print(cumA)
#print(cumB)

ans = 0

for i in range(N+1):
    cnt = i
    chk = K - cumA[i]
    if chk < 0:
        continue
    cnt += bisect.bisect_right(cumB,chk)-1
    ans = max(ans,cnt)
    #print(ans)
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()))
bc = [0]*(m+1)
for i in range(m):
    bc[i+1] = bc[i] + b[i]
bc = bc[1:]

ans = bisect.bisect_right(bc, k) # 0冊
totala = 0
na = 0
for i in range(n):
    totala += a[i]
    na += 1
    if totala == k:
        ans = max(ans, na)
        break
    elif totala > k:
        break
    ba = bisect.bisect_right(bc, k-totala)
    ans = max(ans, na+ba)
print(ans)

Submission status: Accepted

Solution code:
inpl = lambda: list(map(int,input().split()))
N, M, K = inpl()
A = inpl()
B = inpl()
k = 0
for i in range(N):
    if k + A[i] <= K:
        k += A[i]
    else:
        break
else:
    i += 1
for j in range(M):
    if k + B[j] <= K:
        k += B[j]
    else:
        break
else:
    j += 1

ans = i + j
for i in range(i-1,-1,-1):
    k -= A[i]
    while j < M and k + B[j] <= K:
        k += B[j]
        j += 1
    if i + j > ans:
        ans = i + j
    if j == M:
        break
print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

from bisect import bisect_left,bisect_right
def main():
    N,M,K = map(int,input().split())
    A = [0] + list(map(int,input().split()))
    B = [0] + list(map(int,input().split()))
    for i in range(N):
        A[i + 1] += A[i]
    for i in range(M):
        B[i + 1] += B[i]
    
    ans = 0
    for i in range(N + 1):
        idx = bisect_left(B,K - A[i])
        if 0 <= idx <= M and A[i] + B[idx] == K:
            ans = max(ans,i + idx)
        else:
            idx -= 1
            if idx >= 0:
                ans = max(ans,i + idx)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N,M,K=map(int, input().split())
A = [0]
B = [0]
A += list(map(int, input().split()))
B += list(map(int, input().split()))
for i in range(N):
  A[i+1] += A[i]
for i in range(M):
  B[i+1] += B[i]
j = 0
ans = 0
for i in range(N,-1,-1):
  while (j <= M) and (A[i] + B[j] <= K):
    ans = max(ans, i+j)
#    print(i,j,A[i],B[j], A[i] + B[j], ans)
    j += 1
print(ans)

Submission status: Accepted

Solution code:
import numpy as np 
import bisect
N,M,K = map(int,input().split())
a_list = np.array([0]+list(map(int,input().split())))
b_list = np.array(list(map(int,input().split())))


a_list = a_list.cumsum()
b_list = b_list.cumsum()

max_cnt = 0
for i in range(N+1):
    if a_list[i]>K:
        continue
    cnt = i
    bT = K - a_list[i] + 1
    cnt += bisect.bisect_left(b_list,bT)
    if cnt >max_cnt:
        max_cnt = cnt

print(max_cnt)

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip("\r\n")

n, m, k = map(int, input().split())
a = [0] + [int(x) for x in input().split()]
b = [0] + [int(x) for x in input().split()]

from itertools import accumulate

a = list(accumulate(a))
b = list(accumulate(b))
ans = 0
import bisect
for i in range(n + 1):
    now = a[i]
    if k - now >= 0:
        j = bisect.bisect_right(b, k - now)
        ans = max(ans, i + j - 1)
print(ans)

Submission status: Accepted

Solution code:
#from collections import deque,defaultdict
from sys import stdin
input = stdin.readline
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

import bisect
n,m,k = inm()
a = inl()
b = inl()
acca = [0]*(n+1)
accb = [0]*(m+1)
for i in range(n):
    acca[i] = acca[i-1]+a[i]
acca.pop()
for i in range(m):
    accb[i] = accb[i-1]+b[i]
mx = 0 #bisect.bisect_left(a,k+1)
for i in range(m+1):
    x = 0 if i==0 else accb[i-1]
    if x>k:
        break
    j = bisect.bisect_left(acca,k-x+1)
    #ddprint(f"{i=} {mx=} {x=} {j=}")
    mx = max(mx, i+j)
print(mx)

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_r = [0 for _ in range(n+1)]
for i in range(n):
	a_r[i+1] = a_r[i] + a[i]

b_r = [0 for _ in range(m+1)]
for i in range(m):
	b_r[i+1] = b_r[i] + b[i]

ans = 0

for i in range(n+1):
	targ = a_r[i]
	if targ > k:
		break
	ans = max(ans, i-1+bisect.bisect_right(b_r, k-targ))

print(ans)

Submission status: Accepted

Solution code:
N,M,K = map(int,input().rstrip().split(" "))
A = list(map(int,input().rstrip().split(" ")))
B = list(map(int,input().rstrip().split(" ")))
A.append(10 ** 10)
B.append(10 ** 10)
Ai = 0
ans = 0
karians = 0
Aii = 0
Bii = 0
for i in range(N + 1):
    Ai += A[i]
    if Ai > K:
        Ai -= A[i]
        karians = i
        Aii = i
        ans = i
        break
for i in range(Aii + 1):
    while Ai <= K:
        Ai += B[Bii]
        karians += 1
        Bii += 1
    karians -= 1
    Bii -= 1
    Ai -= B[Bii]
    if karians > ans:
        ans = karians
    Ai -= A[Aii - 1 - i]
    karians -= 1
print(ans)

Submission status: Accepted

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


A1 = [0] * (N + 1)
B1 = [0] * (M+1)
A1[1] = A[0]
B1[1] = B[0]

for i in range(2, N+1):
    A1[i] = A[i-1] + A1[i-1]
for i in range(2, M+1):
    B1[i] = B[i-1] + B1[i-1]

ans = 0
t = 0

for i in range(N+1):
    if A1[i] <= K:
        j = bisect_right(B1, K-A1[i])
        ans = max(ans, i + j-1)
    else:
        break


print(ans)

Submission status: Accepted

Solution code:
# import sys
# input = sys.stdin.readline

def mp(): return map(int, input().split())
def lmp(): return list(map(int, input().split()))

n,m,k = mp()
a = lmp()
b = lmp()
a.append(int(1e12))
b.append(int(1e13))
ans = -1

def cum_sum(lst):
    cums = [0] * (len(lst)+1)
    cums[1] = lst[0]
    for i in range(2,len(lst)+1):
        cums[i] = cums[i-1] + lst[i-1]
    return cums

a = cum_sum(a)
b = cum_sum(b)
import bisect
for i in range(len(a)-1):
    can_use = k-a[i]
    if can_use < 0:
        continue
    u = bisect.bisect_right(b, can_use)
    cnt = i + u - 1
    ans = max(ans, cnt)
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
from itertools import accumulate
from bisect import bisect_right
sys.setrecursionlimit(10**8)
INF = float("inf")


def main():
    N, M, K = map(int, input().split())
    A = list(map(int, input().split())) + [INF]
    B = list(map(int, input().split())) + [INF]
    A = [0]+list(accumulate(A))
    B = [0]+list(accumulate(B))

    ans = 0
    for i in range(N+1):
        # Aの山からi冊読んだ場合
        j = bisect_right(B, K-A[i])-1
        if j < 0:
            continue
        ans = max(i+j, ans)
    print(ans)

    return


if __name__ == '__main__':
    main()

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()))
asu=[]
s=0
for i in a:
  s+=i
  asu.append(s)
asu.append(0)
bsu=[]
s=0
for i in b:
  s+=i
  bsu.append(s)
bsu.append(0)
ac=n-1
bc=-1
maxc=0

while (bc!=m)and(ac>=-1):
  while (bc!=m) and (asu[ac]+bsu[bc]<=k):
    bc+=1
  if asu[ac]+bsu[bc-1]<=k:
    maxc=max(maxc,ac+bc+1)
  ac-=1
print(maxc)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from itertools import accumulate
from bisect import bisect

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
sa = [0] + list(accumulate(a))
sb = [0] + list(accumulate(b))
ans = 0
for i in range(n + 1):
    if sa[i] > k:
        continue
    j = bisect(sb, k - sa[i])
    ans = max(ans, i + j)
print(ans - 1)

Submission status: Accepted

Solution code:
n, m, limit = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

x = 0
y = 0
t = 0
while x < n and t + A[x] <= limit:
    t += A[x]
    x += 1
while y < m and t + B[y] <= limit:
    t += B[y]
    y += 1

max_x = x + y

while x > 0:
    x -= 1
    t -= A[x]
    while y < m and t + B[y] <= limit:
        t += B[y]
        y += 1
    if x + y > max_x:
        max_x = x + y

print(max_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()))
from itertools import accumulate
ar=[0]+list(accumulate(a))
bru=[0]+list(accumulate(b))
from bisect import bisect_left as bl,bisect_right as br
ans=0
nb=0
for i in range(n,-1,-1):
    if ar[i]>k:continue
    while nb<m and ar[i]+bru[nb]<k:
        nb+=1
    if ar[i]+bru[nb]>k:nb-=1
    ans=max(ans,i+nb)

print(ans)