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: Time Limit Exceeded

Solution code:
from collections import deque

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

result = 0

a, b = 0, 0
na, nb = 0, 0
for i in range(len(A)):
    if a+A[i] <= K:
        a += A[i]
        na += 1
    else:
        break
for i in range(len(B)):
    if b+B[i] <= K:
        b += B[i]
        nb += 1
    else:
        break

while A != deque() and K >= A[0]:
    if na > nb:
        result += 1
        na -= 1
        K -= A.popleft()
    elif na == nb:
        result += 1
        if A[0] <= B[0]:
            na -= 1
            K -= A.popleft()

while B != deque() and K >= B[0]:
    if na < nb:
        result += 1
        nb -= 1
        K -= B.popleft()
    elif na == nb:
        result += 1
        if A[0] > B[0]:
            nb -= 1
            K -= B.popleft()

print(result)

Submission status: Time Limit Exceeded

Solution code:
from itertools import accumulate
N, M, K = map(int, input().split())
A = [0] + list(map(int, input().split()))
B = [0] + list(map(int, input().split()))
A = list(accumulate(A))
B = list(accumulate(B))
ans = 0
for n in range(N+1):
    for m in reversed(range(M+1)):
        if A[n] + B[m] <= K:
            ans = max(ans, n+m)
            break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import accumulate
N, M, K = map(int, input().split())
A = [0] + list(accumulate([int(i) for i in input().split()]))
B = [0] + list(accumulate([int(i) for i in input().split()]))
ans = 0
for n in range(N+1):
    for m in reversed(range(M+1)):
        if A[n] + B[m] <= K:
            ans = max(ans, n+m)
            break
print(ans)

Submission status: Time Limit Exceeded

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

result = 0

a, b = 0, 0
na, nb = 0, 0
for i in range(len(A)):
    if a+A[i] <= K:
        a += A[i]
        na += 1
    else:
        break
for i in range(len(B)):
    if b+B[i] <= K:
        b += B[i]
        nb += 1
    else:
        break

while A != [] and K >= A[0] or B != [] and K >= B[0]:
    if na > nb:
        result += 1
        na -= 1
        K -= A.pop(0)
    elif na < nb:
        result += 1
        nb -= 1
        K -= B.pop(0)
    elif na == nb:
        result += 1
        if A[0] <= B[0]:
            na -= 1
            K -= A.pop(0)
        else:
            nb -= 1
            K -= B.pop(0)


print(result)

Submission status: Time Limit Exceeded

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

result = 0

while A != [] and K >= A[0] or B != [] and K >= B[0]:
    a, b = 0, 0
    na, nb = 0, 0
    for i in range(len(A)):
        if a+A[i] <= K:
            a += A[i]
            na += 1
        else:
            break
    for i in range(len(B)):
        if b+B[i] <= K:
            b += B[i]
            nb += 1
        else:
            break
    if na > nb:
        K -= A.pop(0)
        result += 1
    elif na < nb:
        K -= B.pop(0)
        result += 1
    elif na == nb:
        if A[0] <= B[0]:
            K -= A.pop(0)
        else:
            K -= B.pop(0)
        result += 1

print(result)

Submission status: Time Limit Exceeded

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

a = [0] * (N+1)
b = [0] * (M+1)
for i,x in enumerate(A):
    a[i+1] = a[i] + x

for i,x in enumerate(B):
    b[i+1] = b[i] + x

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

Submission status: Time Limit Exceeded

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

a = [0] * (N+1)
b = [0] * (M+1)
for i,x in enumerate(A):
    a[i+1] = a[i] + x

for i,x in enumerate(B):
    b[i+1] = b[i] + x

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

Submission status: Time Limit Exceeded

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

acum = [0]
for x in a:
    acum += [acum[-1] + x]

total = [0] * (n+1)
ans = [0] * (n+1)
cnt = 0
for i,v in enumerate(acum):
    if v > k:
        continue
    total[i] += v
    ans[i] += i
    j = 0
    for j, vv in enumerate(b):
        if total[i] > k:
            break
        if total[i] + b[j] > k:
            break
        if j >= m:
            break

        total[i] += b[j]
        ans[i] += 1
        j += 1
    #print(acum[i], j, ans[i], total[i])
    cnt = max(cnt, ans[i])
print(cnt)

Submission status: Time Limit Exceeded

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

# print(K)
# print(a)
# print(b)
# N,M=3,4
# K=730
# a=[60, 90, 120]
# b=[80, 150, 80, 150]

ans=0

accum_a=[0]
for i in a:
    _a=accum_a[-1]+i
    if _a>K:
        break
    else:
        accum_a.append(_a)
accum_a.append(K)

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

ans=0

for j in range (len(accum_a)-1):
    Kb=K-accum_a[j]
    _accum_b=accum_b
    _accum_b.append(Kb)
    _accum_b1=sorted(_accum_b)
    bookb=_accum_b1.index(Kb)-1
    if _accum_b.count(Kb)==2:
        bookb+=1
    if j+bookb>ans:
        ans=j+bookb
    else:
        continue
print(ans)

Submission status: Time Limit Exceeded

Solution code:
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[i] + A[i])

for i in range(m):
    b.append(b[i] + B[i])

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

Submission status: Time Limit Exceeded

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

a = [0] + list(map(int, input().split()))
b = list(map(int, input().split()))
cnt = 0
cnta = 0
ans = 0


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

Submission status: Time Limit Exceeded

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(n + 1):
    cnt = sum(a[:i])
    if cnt > k:
        ans = max(ans, i - 1)
        break
    for j in range(m):
        cnt += b[j]
        if cnt > k:
            ans = max(ans, i + j)
            break
    else:
        ans = max(ans, i + j + 1)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
input = lambda: stdin.readline().rstrip("\r\n")
from collections import defaultdict as vector, deque as que
read = lambda: list(map(int,input().split()))
from bisect import bisect
from heapq import heappush as hpush,heappop as hpop

n,m,k=read()
A=read()
B=read()
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
for i in range(0,n+1):
	curr=a[i]
	j=m
	if curr>k:
		break
	while(b[j]>k-curr):
		j-=1
	ans=max(ans,i+j)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
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):
    a[i] = a[i-1] + a[i]
for i in range(1, M+1):
    b[i] = b[i-1] + b[i]

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

Submission status: Time Limit Exceeded

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


def Cum(X):
    temp = 0
    Cum = [0]*len(X)
    for i in range(len(X)):
        temp += X[i]
        Cum[i] += temp
    return Cum

a = Cum(A)
a.insert(0,0)
b = Cum(B)
b.insert(0,0)

na = 0
for i in range(N+1):
    if i == N and a[i]<=K:
        na = N
    elif a[i]<=K and a[i+1]>K:
        na = i

ans = na

nb = 0
for i in range(na,-1,-1):
    temp = K-a[i]
    for j in range(nb,M+1):
        if j == M and b[j] <= temp:
            nb = M
        elif b[j]<=temp and b[j+1]>temp:
            nb = j
        ans = max(ans,i+nb)
        
print(ans)

Submission status: Time Limit Exceeded

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


def Cum(X):
    temp = 0
    Cum = [0]*len(X)
    for i in range(len(X)):
        temp += X[i]
        Cum[i] += temp
    return Cum

a = Cum(A)
a.insert(0,0)
b = Cum(B)
b.insert(0,0)


def f(X,x,target):
    return X[x]-target

def nibutan(X):
    num = list(range(len(X)))
    lo = 0
    hi = len(X)
    while hi-lo>=2:
        mid = (lo+hi)//2
        if f(X,mid,Y)<=0:
            lo = mid
        else:
            hi = mid
    return lo

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

Submission status: Time Limit Exceeded

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

# print(N, M, K)
# print(A)
# print(B)

def cuml(li):
    rlis = [0]

    for i in range(len(li)):
        rlis.append(rlis[-1] + li[i])

    return rlis


A_cuml = cuml(A)
B_cuml = cuml(B)

res = 0

for a in range(len(A_cuml)):
    if A_cuml[a] > K:
        break
    for b in range(len(B_cuml)):
        if A_cuml[a] + B_cuml[b] > K:
            break
        
        res = max(res, a + b)

print(res)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import functools
import math
from collections import Counter
from itertools import combinations
import re



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

    A_len = len(A)
    B_len = len(B)

    Asum = [0] * (A_len + 1)
    Bsum = [0] * (B_len + 1)

    maxA = 0
    maxB = 0

    add = 0
    for i in range(1,A_len+1):
        add += A[i-1]
        Asum[i] = add
        if add <= K:
            maxA = i + 1
        else:
            break

    add = 0
    for i in range(1,B_len+1):
        add += B[i-1]
        Bsum[i] = add
        if add <= K:
            maxB = i + 1
        else:
            break

    ans = 0
    prevmax = 0
    for i in reversed(range(maxA)):
        for j in range(prevmax,maxB):
            if Asum[i] + Bsum[j] <= K:
                if ans < i + j:
                    ans = i + j
                    prevmax = j
            else:
                break
            if j == maxB - 1:
                print(ans)
                exit()

    print(ans)

main_sum()

Submission status: Time Limit Exceeded

Solution code:
import itertools
import functools
import math
from collections import Counter
from itertools import combinations
import re



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

    A_len = len(A)
    B_len = len(B)

    Asum = [0] * (A_len + 1)
    Bsum = [0] * (B_len + 1)

    maxA = 0
    maxB = 0

    add = 0
    for i in range(1,A_len+1):
        add += A[i-1]
        Asum[i] = add
        if add <= K:
            maxA = i + 1
        else:
            break

    add = 0
    for i in range(1,B_len+1):
        add += B[i-1]
        Bsum[i] = add
        if add <= K:
            maxB = i + 1
        else:
            break

    ans = 0
    prevmax = 0
    for i in reversed(range(maxA)):
        for j in range(prevmax,maxB):
            if Asum[i] + Bsum[j] <= K:
                if ans < i + j:
                    ans = i + j
                    prevmax = j
            else:
                break

    print(ans)

main_sum()

Submission status: Time Limit Exceeded

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

A_sum = [0] + [sum(A[:i+1]) for i in range(len(A))]
B_sum = [0] + [sum(B[:i+1]) for i in range(len(B))]
B_sum.append(10**20)

res = 0
for i in range(len(A_sum)):
    low = 0
    high = len(B_sum)
    while high - low > 1:
        mid = (low + high) // 2
        if A_sum[i] + B_sum[mid] <= K:
            low = mid
        else:
            high = mid
    if A_sum[i] + B_sum[low] <= K:
        res = max(res, i + low)

print(res)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import functools
import math
from collections import Counter
from itertools import combinations
import re



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

    A_len = len(A)
    B_len = len(B)

    Asum = [0] * (A_len + 1)
    Bsum = [0] * (B_len + 1)

    maxA = 0
    maxB = 0

    add = 0
    for i in range(1,A_len+1):
        add += A[i-1]
        Asum[i] = add
        if add <= K:
            maxA = i + 1

    add = 0
    for i in range(1,B_len+1):
        add += B[i-1]
        Bsum[i] = add
        if add <= K:
            maxB = i + 1

    ans = 0
    prevmax = 0
    for i in reversed(range(maxA)):
        for j in range(prevmax,maxB):
            if Asum[i] + Bsum[j] <= K:
                if ans < i + j:
                    ans = i + j
                    prevmax = j
            else:
                break

    print(ans)

main_sum()

Submission status: Time Limit Exceeded

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

A_sum = [0] + [sum(A[:i+1]) for i in range(len(A))]
B_sum = [0] + [sum(B[:i+1]) for i in range(len(B))]

res = 0
for i in range(len(A_sum)):
    low = 0
    high = len(B_sum)
    while high - low > 1:
        mid = (low + high) // 2
        if A_sum[i] + B_sum[mid] <= K:
            low = mid
        else:
            high = mid
    if A_sum[i] + B_sum[low] <= K:
        res = max(res, i + low)

print(res)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import functools
import math
from collections import Counter
from itertools import combinations
import re



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

    A_len = len(A)
    B_len = len(B)

    Asum = [0] * (A_len + 1)
    Bsum = [0] * (B_len + 1)

    maxA = 0
    maxB = 0

    add = 0
    for i in range(1,A_len+1):
        add += A[i-1]
        Asum[i] = add
        if add <= K:
            maxA = i + 1

    add = 0
    for i in range(1,B_len+1):
        add += B[i-1]
        Bsum[i] = add
        if add <= K:
            maxB = i + 1

    ans = 0
    for i in reversed(range(maxA)):
        for j in range(maxB):
            if Asum[i] + Bsum[j] <= K:
                if ans < i + j:
                    ans = i + j

    print(ans)




main_sum()

Submission status: Time Limit Exceeded

Solution code:
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

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

A_sum = [0]
B_sum = [0]
for i in range(N):
    A_sum.append(A_sum[-1] + A[i])
for i in range(M):
    B_sum.append(B_sum[-1] + B[i])

ans = 0
for i in range(N+1):
    for j in range(M, -1, -1):
        time = A_sum[i] + B_sum[j]
        if time > K:
            continue
        ans = max(i + j, ans)
        break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

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

A_sum = [0]
B_sum = [0]
for i in range(N):
    A_sum.append(A_sum[-1] + A[i])
for i in range(M):
    B_sum.append(B_sum[-1] + B[i])

ans = 0
for i in range(N+1):
    for j in range(M+1):
        time = A_sum[i] + B_sum[j]
        if time > K:
            break
        ans = max(i + j, ans)
print(ans)

Submission status: Time Limit Exceeded

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(a[i] + arui[i])
for i in range(M):
    brui.append(b[i] + brui[i])

ans = 0
for i in range(N + 1):
    if arui[i] > K:
        break
    bcnt = M
    while brui[bcnt] + arui[i] > K:
        bcnt -= 1
    ans = max(ans, i + bcnt)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, M, K = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
arui = [0] * (N + 1)
brui = [0] * (M + 1)
for i in range(N):
    arui[i + 1] = a[i] + arui[i]
for i in range(M):
    brui[i + 1] = b[i] + brui[i]

ans = 0
for i in range(N + 1):
    if arui[i] > K:
        break
    bcnt = M
    while brui[bcnt] + arui[i] > K:
        bcnt -= 1
    ans = max(ans, i + bcnt)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
i = 0
j = 0
count = 0
sum_A = 0
sum_B = 0
for i in range(N+1):
	if(i != 0):
		sum_A += A[i-1]
	if sum_A > K:
		break
	for j in range(M+1):
		if(j != 0):
			sum_B += B[j-1]
		else:
			sum_B = 0
		if sum_A + sum_B <= K:
			tmp = i + j
			count = max(tmp, count)
		else:
			break
print(count)

Submission status: Time Limit Exceeded

Solution code:
import bisect

N, M, K = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
cmplst = a
index = 0
for i in range(M):
    tmp = bisect.bisect_right(cmplst[index:], b[i])
    cmplst.insert(tmp + index, b[i])
    index = tmp

rui = [0] * (N + M + 1)
for i in range(N + M):
    rui[i + 1] = cmplst[i] + rui[i]

tmp = bisect.bisect_left(rui, K)
if rui[tmp] == K:
    print(tmp)
else:
    print(tmp - 1)

Submission status: Time Limit Exceeded

Solution code:
na,nb,k = map(int, input().split())
ta = list(map(int, input().split()))
tb = list(map(int, input().split()))
 
 
def get_bcnt( usek,tb=tb ):
    tb_sum = [ sum(tb[:i]) + tt for i, tt in enumerate(tb)]
    tb_sum_tf = [ i <= usek for i in tb_sum]
    
    if False in tb_sum_tf:
        return tb_sum_tf.index(False)
    else:
        return len(tb)
    
 
readbook = [ i+1 + get_bcnt( k - sum( ta[:i] ) )  for i in range(na) if sum( ta[:i+1] ) <= k ]
readbook.append( get_bcnt(k) )
print( max(readbook) )

Submission status: Time Limit Exceeded

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

count = 0
time_counter = 0
while A or B:
    if A and B:
        if A[0] <= B[0]:
            if time_counter + A[0] <= k:
                time_counter += A[0]
                count += 1
            A.pop(0)
        else:
            if time_counter + B[0] <= k:
                time_counter += B[0]
                count += 1
            B.pop(0)
    elif not A:
        if time_counter + B[0] <= k:
            time_counter += B[0]
            count += 1
        B.pop(0)
    else:
        if time_counter + A[0] <= k:
            time_counter += A[0]
            count += 1
        A.pop(0)
print(count)

Submission status: Time Limit Exceeded

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

n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
res = 0
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])

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

print(res)

Submission status: Time Limit Exceeded

Solution code:
import bisect
from collections import deque
n,m,k=map(int,input().split())
a=deque(map(int,input().split()))
b=deque(map(int,input().split()))
a_sum=deque()
b_sum=deque()
a_sum.append(0)
b_sum.append(0)
for i in range(n):
    a_sum.append(a_sum[i]+a[i])
for j in range(m):
    b_sum.append(b_sum[j]+b[j])
ans=0
for x in range(n+1):
    timecount=k-a_sum[x]
    if timecount>=0:
        y=bisect.bisect_right(b_sum,k-a_sum[x])-1
        ans=max(x+y,ans)
    else:
        break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, M, K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
sum_list = []
for i in range(N+1):
  if K < sum(A[:i]):
    break
  for j in range(M+1):
    sum_ = sum(A[:i]) + sum(B[:j])
    if sum_ <= K:
      sum_list.append(len(A[:i]) + len(B[:j]))
    elif K < sum_:
      break
if 1 <= len(sum_list):
  print(max(sum_list))
elif 0 == len(sum_list):
  print(0)

Submission status: Time Limit Exceeded

Solution code:
N, M, K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
sum_list = []
for i in range(N+1):
  for j in range(M+1):
    sum_ = sum(A[:i]) + sum(B[:j])
    if sum_ <= K:
      sum_list.append(len(A[:i]) + len(B[:j]))
    elif K < sum_:
      break
if 1 <= len(sum_list):
  print(max(sum_list))
elif 0 == len(sum_list):
  print(0)

Submission status: Time Limit Exceeded

Solution code:
x,y,z= map(int,input().split())
left = list(map(int,input().split()))
right = list(map(int,input().split()))
array = left+right
array.sort()
#print(array)
x=[]
s=0
for i in range(len(array)):
  s+=array.pop(0)
  x.append(s)
  #print(sum(x))
  if (s > z):
    x.pop(-1)
    break
#print(left+right)
#print(z)
#print(sum(x))
#print(x)
print(len(x))

Submission status: Time Limit Exceeded

Solution code:
x,y,z= map(int,input().split())
left = list(map(int,input().split()))
right = list(map(int,input().split()))
array = left+right
array.sort()
#print(array)
x=[]
for i in range(len(array)):
  x.append(array.pop(0))
  #print(sum(x))
  if (sum(x) > z):
    x.pop(-1)
    break
#print(left+right)
#print(z)
#print(sum(x))
#print(x)
print(len(x))

Submission status: Time Limit Exceeded

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

l_l=[0]
for i in range(1,m+1):
  l_l.append(l_l[i-1]+ll[i-1])

ans=0
for i in range(m+1):
  if l_l[i]>k:
    break
  
  sm=0
  j=0
  while j<n and l_l[i]+sm+l[j]<=k:
    sm+=l[j]
    j+=1
  ans=max(ans,i+j)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
a,b,k = map(int,input().split(" "))
r = list(map(int,input().split(" ")))
l = list(map(int,input().split(" ")))
ar = [0]
br = [0]
for i in range(a):
    ar.append(ar[-1] + r[i])
for i in range(b):
    br.append(br[-1] + l[i])
ans = 0
for i in range(len(ar)):
    if ar[i] > k:
        break
    for j in range(len(br)):
        if ar[i] + br[j] <= k:
            t = i + j
        else:
            break
        ans = max(ans,t)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
a,b,k = map(int,input().split(" "))
r = list(map(int,input().split(" ")))
l = list(map(int,input().split(" ")))
ar = [0]
br = [0]
for i in range(a):
    if ar[-1] + r[i] <= k:
        ar.append(ar[-1] + r[i])
    else:
        break 
for i in range(b):
    if br[-1] + l[i] <= k:
        br.append(br[-1] + l[i])
    else:
        break 
ans = 0
for i in range(len(ar)):
    for j in range(len(br)):
        if ar[i] + br[j] <= k:
            t = i + j
        ans = max(ans,t)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

n, m, k = map(int, input().split())
A = [0] + list(map(int, input().split()))
B = [0] + list(map(int, input().split()))

A = list(itertools.accumulate(A))
B = list(itertools.accumulate(B))

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

Submission status: Time Limit Exceeded

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

l_ans=[]
for i in range(m+1):
  l_ans.append([0]*(n+1))
ct=0

for i in range(m+1):
  we=i+n
  for j in range(n+1):
    if i==0 and j==0:
      l_ans[i][j]=0
    elif i==0:
      l_ans[i][j]=l_ans[i][j-1]+l[j-1]
    elif j==0:
      l_ans[i][j]=l_ans[i-1][j]+ll[i-1]
    else:
      l_ans[i][j]=l_ans[i][j-1]+l[j-1]
    
    if l_ans[i][0]>k:
      we=0
      break
    if l_ans[i][j]>k:
      we=i+j-1
      break
    elif l_ans[i][j]==k:
      we=i+j
      break
  
  #print(ct,we)

  if we>ct:
    ct=we
#print(l_ans)
print(ct)

Submission status: Time Limit Exceeded

Solution code:
n, m, k = tuple(map(int, input().split()))
xs = list(map(int, input().split()))
ys = list(map(int, input().split()))

readed = 0
t = 0
while True:
    x_len = len(xs)
    y_len = len(ys)
    if x_len >= 1 and (xs[0] + t <= k):
        n = xs.pop(0)
        t += n
        readed += 1
    elif y_len >= 1 and (ys[0] + t <= k):
        n = ys.pop(0)
        t += n
        readed += 1
    else:
        break

print(readed)

Submission status: Time Limit Exceeded

Solution code:
n, m, k = map(int, input().strip().split())

a = list(map(int, input().strip().split()))[:n]
b = list(map(int, input().strip().split()))[:m]
  
all = []
all.extend(a)
all.extend(b)

counter = 0
am = 0
while(k - min(all) >= 0):
    am = min(all)
    k -= am
    counter += 1
    all.remove(am)
    if(len(all) == 0):
        break
  
  
print(counter)

Submission status: Time Limit Exceeded

Solution code:
n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
pa, pb = [0] * (n+1), [0] * (m+1)
for i in range(n):
    pa[i+1] = pa[i] + a[i]
for i in range(m):
    pb[i+1] = pb[i] + b[i]
mx = 0
for i in range(len(pa)):
    j = m
    if pa[i] > k:
        break
    v = k - pa[i]
    while pb[j] > v:
        j -= 1
    mx = max(mx, i+j)
print(mx)

Submission status: Time Limit Exceeded

Solution code:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A_acc = [0] * (N + 1)
B_acc = [0] * (M + 1)
acc = 0
for i, a in enumerate(A):
    acc += a
    A_acc[i+1] = acc
acc = 0
for i, b in enumerate(B):
    acc += b
    B_acc[i+1] = acc
ans = 0
for i in range(N + 1):
    if A_acc[i] > K:
        break
    for j in range(M,-1,-1):
        if A_acc[i] + B_acc[j] <= K:
            ans = max(ans, i + j)
            break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A_acc = [0]
B_acc = [0]
acc = 0
for a in A:
    acc += a
    A_acc.append(acc)
acc = 0
for b in B:
    acc += b
    B_acc.append(acc)
ans = 0
for i in range(N + 1):
    if A_acc[i] > K:
        break
    for j in range(M,-1,-1):
        if A_acc[i] + B_acc[j] <= K:
            ans = max(ans, i + j)
            break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = 0
sum_a = 0
for i in range(len(A)+1):
    if i == 0:
        sum_a = 0
    else:
        sum_a += A[i-1]
    if sum_a > K:
        break
    sum_b = 0
    for j in range(len(B)+1):
        if j == 0:
            sum_b = 0
        else:
            sum_b += B[j-1]
        if sum_b > K - sum_a:#Bを全部読み切れない場合
            ans = max(ans, i+j-1)
            break
        if j == len(B): #Bを全部読み切れる場合
            ans = max(ans, i+j)
print(ans)

Submission status: Time Limit Exceeded

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


def cumsum(l):
    s = 0
    for v in l:
        s += v
        yield s


a = (0,) + tuple(cumsum(A))
b = (0,) + tuple(cumsum(B))
ans = 0
m = M
for i in range(N + 1):
    if a[i] > K:
        continue
    for j in range(m, -1, -1):
        if a[i] + b[j] <= K:
            k = j
            break
        else:
            continue
    ans = max(ans, i + j)
print(ans)

Submission status: Time Limit Exceeded

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

a = list(map(int,input().split()))

b = list(map(int,input().split()))


ans = 0

aa = 0

for i in range(n+1):
    cnt = 0
    x = k
    x -= aa
    if i != n:
        aa += a[i]
    
    if x<0:
        break
    
    while x>0 and cnt<m:
        x -= b[cnt]
        cnt += 1
        
    if x<0:
        cnt -= 1
        
    ans = max(ans,cnt+i)
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
pa, pb = [0] * (n+1), [0] * (m+1)
for i in range(n):
    pa[i+1] = pa[i] + a[i]
for i in range(m):
    pb[i+1] = pb[i] + b[i]
m = 0
for i in range(len(pa)):
    if pa[i] > k:
        break
    v = k - pa[i]
    for j in range(len(pb)):
        if pb[j] > v:
            m = max(m, i+j-1)
            break
    else:
        m = max(m, i+j)
print(m)