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:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
aa=[0]
num=0

maxcount,count,bcount,bb,aaa=0,0,0,0,0
kk=k

for i in a:
  aaa+=i
  aa.append(i+aa[num])
  num+=1
  
  if aaa<=k:
    count+=1
    
acount=count
count=0
  
del aa[0]
  
for i in b:
  bb+=i
  bcount+=1
  k-=bb
  
  if k<=0:
    break
  
  for j in aa:
    if j<=k:
      count+=1
      
    else:
      break
      
  count+=bcount
  
  if count>maxcount:
    maxcount=count
  
  count=0
      
  k=kk
      
print(maxcount if acount<maxcount else acount)

Submission status: Time Limit Exceeded

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

answer = -float('inf')
order = list(itertools.permutations([1]*n+[0]*m))
order2 = set(order)
for o in order2:
  acur, bcur = 0, 0
  books = 0
  time = 0
  for i in o:
    books += 1
    if i:
      time += a[acur]
      acur += 1
    else:
      time += b[bcur]
      bcur += 1
    if time == k:
      answer = max(answer, books)
      break
    elif time > k:
      answer = max(answer, books-1)
      break
print(answer)

Submission status: Time Limit Exceeded

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

a_ls = [0] + list(map(int, input().split(' ')))
b_ls = [0] + list(map(int, input().split(' ')))

for i in range(1, n+1):
    a_ls[i] += a_ls[i-1]
for i in range(1, m+1):
    b_ls[i] += b_ls[i-1]

for a_cnt in range(0, n+1):
    if a_ls[a_cnt] > k:
        continue
    b_cnt = m
    while a_ls[a_cnt] + b_ls[b_cnt] > k:
        b_cnt -= 1
    ans = max(ans, a_cnt + b_cnt)

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

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


num = 0
for i in range(N+1):
    for j in range(M+1):
        if A_sum[i]+B_sum[j] <= K:
            if num < i+j:
                num = i+j

print(num)

Submission status: Time Limit Exceeded

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

asumlist = list([0])
asum = 0
for n in range(N):
  asum += alist[n]
  if K >=asum:
    asumlist.append(asum)
  else:
    break

bsumlist = list([0])
bsum = 0
for m in range(M):
  bsum += blist[m]
  if K >=bsum:
    bsumlist.append(bsum)
  else:
    break

max_b=0
for n in range(len(asumlist)):
  for m in range(len(bsumlist)):
    if K >= asumlist[n]+bsumlist[m]:
      b = n + m
      if max_b < b:
        max_b = b
    else:
      break
  else:
    b = n + len(bsumlist)-1
    if max_b < b:
      max_b = b
else:
  b = len(asumlist) + len(bsumlist)-2
  if asumlist[-1]+bsumlist[-1] <= K and max_b < b:
    max_b = b
print(max_b)

Submission status: Time Limit Exceeded

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

asumlist = list([0])
for n in range(N):
  if K >=sum(alist[0:n+1]):
    asumlist.append(sum(alist[0:n+1]))
  else:
    break

bsumlist = list([0])
for m in range(M):
  if K >=sum(blist[0:m+1]):
    bsumlist.append(sum(blist[0:m+1]))
  else:
    break

max_b=0
for n in range(len(asumlist)):
  for m in range(len(bsumlist)):
    if K >= asumlist[n]+bsumlist[m]:
      b = n + m
      if max_b < b:
        max_b = b
    else:
      break
  else:
    b = n + len(bsumlist)-1
    if max_b < b:
      max_b = b
else:
  b = len(asumlist) + len(bsumlist)-2
  if asumlist[-1]+bsumlist[-1] <= K and max_b < b:
    max_b = b
print(max_b)

Submission status: Time Limit Exceeded

Solution code:
def main():
    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):
        ans_ = 0
        cost = sum(a[0:i])
        k_ = k-cost
        if k_<0:
            break
        ans_ = i
        for j in range(m):
            k_ = k_-b[j]
            if k_<0:
                break
            ans_ += 1
        if ans_ > ans:
            ans = ans_
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
m, n, k = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
assert(len(a) == m)
assert(len(b) == n)

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

ans = 0

for i in range(m + 1):
  if A[i] > k:
    break
  j = n
  while j > 0 and B[j] > k - A[i]:
    j -= 1
  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

for Abook in range(len(A) + 1):
  for Bbook in range(len(B) + 1):
    time = 0
    for i in range(Abook):
      time = time + A[i]
      if time > k:
        break
    for d in range(Bbook):
      time = time + B[d]
      if time > k:
        break
    if time <= k and ans <= Abook + Bbook:
      ans = Abook + Bbook
    
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 Abook in range(len(A) + 1):
  for Bbook in range(len(B) + 1):
    time = 0
    for i in range(Abook):
      time = time + A[i]
    for d in range(Bbook):
      time = time + B[d]
    if time <= k and ans <= Abook + Bbook:
      ans = Abook + Bbook
    
print(ans)

Submission status: Time Limit Exceeded

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

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

if A_CumulativeSum[n-1] + B_CumulativeSum[m-1] <= k:
    print(n+m)
    sys.exit()

ans = 0
for i in range(n+1):
    time = A_CumulativeSum[i]
    if time > k:
        break
    time_b = k - time
    j = m
    while time_b < B_CumulativeSum[j]:
        j -= 1

    count = i + j
    ans = max(count, ans)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy

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

acc_a = [0]
for i in range(N):
    acc_a.append(acc_a[i] + A[i])

acc_b = [0]
for i in range(M):
    acc_b.append(acc_b[i] + B[i])

acc_a = numpy.array(acc_a)
acc_b = numpy.array(acc_b)

currentMax = 0
for j in range(M + 1):
    tB = acc_b[j]
    remain = K - tB
    # print('-----------')
    # print('Bを{0}冊読んだら，かかる時間は{1}分, 残り時間は{2}分'.format(j, tB, K - tB))
    if remain < 0:
        # print('時間切れで読める本なし')
        break

    # print(numpy.where(acc_a < remain)[0])
    if len(numpy.where(acc_a < remain)[0]) != 0:
        readable = numpy.where(acc_a <= remain)[0][-1]

        # print('残り時間{0}分で読めるAの本は{1}冊'.format(remain, readable))
        # print('トータル{0}冊読める'.format(j + readable))
        currentMax = max(currentMax, j + readable)

print(currentMax)

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(A)
ans = 0
time = 0
#i = 0
#j = 0
while time < K:
    if not A:
        ans += 1
        time += B[0]
        #print(A)
        #print(B)
        B.pop(0)
    elif not B:
        ans += 1
        time += A[0]
        A.pop(0)
        #print(A)
    #    print(B)
    elif A[0] > B[0] :
        #print(B[0])
        time += B[0]
        ans += 1
        B.pop(0)
        #print(A)
        #print(B)
    elif A[0] < B[0]:
        #print(A[0])
        time += B[0]
        ans += 1
        A.pop(0)
        #print(A)
        #print(B)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

book_num = 0

A_accum = [0] + list(itertools.accumulate(A))
B_accum = [0] + list(itertools.accumulate(B))
for n in range(N + 1):
    for m in range(M + 1):
        if K < A_accum[n] + B_accum[m]:
            break
        if book_num < n + m:
            book_num = n + m

print(book_num)

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

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

MAX = 0
i = 0

for j in range(M, -1, -1):
    if ruiA[i] + ruiB[j] <= K:
        MAX = max(MAX, i+j)
        best = j
        break
    

for i in range(1, N+1):
    for j in range(best, -1, -1):
        if ruiA[i] + ruiB[j] <= K:
            MAX = max(MAX, i+j)
            break


print(MAX)

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

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

MAX = 0
for i in range(N+1):
    for j in range(M+1):
        if ruiA[i] + ruiB[j] <= K and i + j > MAX:
            MAX = i + j

print(MAX)

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 = [0]
b = [0]
p = 0
q = 0
for i in range(N):
  if p + A[i] > K:
    break
  a.append(p+A[i])
  p += A[i]
for i in range(M):
  if q + B[i] > K:
    break
  b.append(q+B[i])
  q += B[i]
ans = 0
for n, s in enumerate(a):
  if s > K:
    break
  for m, t in enumerate(b):
    if s + t <= K:
      ans = max(ans, n+m)
    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()))
a = [0]
b = [0]
p = 0
q = 0
for i in range(N):
  a.append(p+A[i])
  p += A[i]
for i in range(M):
  b.append(q+B[i])
  q += B[i]
ans = 0
for n, s in enumerate(a):
  if s > K:
    break
  for m, t in enumerate(b):
    if s + t <= K:
      ans = max(ans, n+m)
    else:
      break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

in_1 = input()
in_2 = input()
in_3 = input()

N, M, K = np.array(in_1.split(' ')).astype(np.int)
A = np.array(in_2.split(' ')).astype(np.longlong)
B = np.array(in_3.split(' ')).astype(np.longlong)

read_count = 0

SA = np.zeros(N + 1).astype(np.longlong)
SB = np.zeros(M + 1).astype(np.longlong)

SA[0] = 0
SB[0] = 0

for n in range(N):
    SA[n + 1] = SA[n] + A[n]

for m in range(M):
    SB[m + 1] = SB[m] + B[m]

for n in range(N + 1):
    if SA[n] > K:
        break

    for m in range(M + 1):
        read_time = SA[n] + SB[m]
        if read_time > K:
            break

        if read_time <= K and read_count < n + m:
            read_count = n + m

print(read_count)

Submission status: Time Limit Exceeded

Solution code:
in_1 = input()
in_2 = input()
in_3 = input()

import numpy as np

N, M, K = np.array(in_1.split(' ')).astype(np.longlong)
A = np.array(in_2.split(' ')).astype(np.longlong)
B = np.array(in_3.split(' ')).astype(np.longlong)

read_count = 0

for n in range(N + 1):
    for m in range(M + 1):
        read_time = np.sum(A[:n]) + np.sum(B[:m])
        if read_time <= K and read_count < n + m:
            read_count = n + m

print(read_count)

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] * (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]
res = 0
for i in range(n+1):
    for j in range(m+1):
        if a_sum[i] + b_sum[j] <= k:
            res = max(res, i + j)
        else:
            break
print(res)

Submission status: Time Limit Exceeded

Solution code:
import math
import sys
import itertools
from math import gcd
from math import sqrt
from sys import stdin
def input() : return stdin.readline().rstrip()
def mips():
    return map(int,input().split())
def ii():
    return int(input())
sys.setrecursionlimit(10**9)

N,M,K = mips()
A = [i for i in mips()]
B = [i for i in mips()]
# N,M <= 200000
ans = 0
clock = K
A2 = [0]
B2 = [0]
for i in range(1,N+1):
    ai = A2[i-1] + A[i-1]
    A2.append(ai)
for i in range(1,M+1):
    bi = B2[i-1] + B[i-1]
    B2.append(bi)
for i in range(N+1):
    j = M
    if A2[i] > K:
        break
    while (B2[j] + A2[i] > K):
        j -= 1
    ans = max(ans,i+j)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
import sys
import itertools
from math import gcd
from math import sqrt
from sys import stdin
def input() : return stdin.readline().rstrip()
def mips():
    return map(int,input().split())
def ii():
    return int(input())
sys.setrecursionlimit(10**9)

N,M,K = mips()
A = [i for i in mips()]
B = [i for i in mips()]
# N,M <= 200000
ans = 0
clock = K
A2 = [0]
B2 = [0]
for i in range(1,N+1):
    ai = A2[i-1] + A[i-1]
    A2.append(ai)
for i in range(1,M+1):
    bi = B2[i-1] + B[i-1]
    B2.append(bi)
for i in range(N+1):
    j = M
    if A2[i] > K:
        break
    while (j >= 0):
        if A2[i] + B2[j] <= K:
            ans = max(ans,i+j)
        j -= 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
import sys
import itertools
from math import gcd
from math import sqrt
from sys import stdin
def input() : return stdin.readline().rstrip()
def mips():
    return map(int,input().split())
def ii():
    return int(input())
sys.setrecursionlimit(10**9)

N,M,K = mips()
A = [i for i in mips()]
B = [i for i in mips()]
# N,M <= 200000
ans = 0
clock = K
A2 = [0]
B2 = [0]
for i in range(1,N+1):
    ai = A2[i-1] + A[i-1]
    A2.append(ai)
for i in range(1,M+1):
    bi = B2[i-1] + B[i-1]
    B2.append(bi)
for i in range(N+1):
    j = M
    while (j >= 0):
        if A2[i] + B2[j] <= K:
            ans = max(ans,i+j)
        j -= 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    N, M, K  = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    bs = M
    ans = 0
    for i in range(N + 1):
        asum = sum(A[:i])
        if asum > K:
            break
        for j in range(bs, -1, -1):
            if sum(B[:j]) + asum <= K:
                bs = j
                break
        ans = max(ans, i + bs)
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
def main():
    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()]
    aa = 0
    bs = 0
    cc = 0
    for i in range(n + 1):
        c = 0
        if sum(a[:i]) > k:
            break
        else:
            aa = sum(a[:i])
            c = i
            for j in range(bs, m + 1):
                if sum(b[:-j if j != 0 else m]) + aa <= k:
                    c += len(b) - j
                    bs = j
                    break
                else:
                    continue
            if c > cc:
                cc = c
    print(cc)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

N,M,K=MI()
A=[0]+LI()
B=[0]+LI()
from itertools import accumulate
A=list(accumulate(A))
B=list(accumulate(B))
ans=0
for i in range(N+1):
  if A[i]>K:
    break
  for j in range(M,-1,-1):
    if A[i]+B[j]>K:
      continue
    ans=max(ans,i+j)
    break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

N,M,K=MI()
A=[0]+LI()
B=[0]+LI()
from itertools import accumulate
A=list(accumulate(A))
B=list(accumulate(B))
ans=0
for i in range(N+1):
  if A[i]>K:
    continue
  for j in range(M,-1,-1):
    if A[i]+B[j]>K:
      continue
    ans=max(ans,i+j)
    break
print(ans)

Submission status: Time Limit Exceeded

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()]
import sys
sys.setrecursionlimit(10**6)
maxc = 0
a_i=0
b_i=0
def dfs(a_i,b_i,t,cnt):
    global maxc
    
    if(a_i==n and b_i==m):
        maxc = m+n
        return
    if(k < t):
        maxc = max(maxc,cnt-1)
        return 
    if(a_i < n):
        dfs(a_i+1,b_i,A[a_i]+t,cnt+1)
 
    if(b_i < m):
        dfs(a_i,b_i+1,B[b_i]+t,cnt+1)
 
 
 
        
dfs(0,0,0,0)
print(maxc)

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(" ")))
max = 0
for i in range(len(A)+1):
  time_a = 0
  if i > 0:
    time_a = sum(A[:i])
  if time_a > K:
    break
  for j in range(len(B)+1):
    time = time_a
    if j > 0:
    	time += sum(B[:j])
    if time > K:
      break
    elif max < i+j:
      max = i+j
print(max)

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(" ")))
max = 0
memo = {"A":0, "B":0, "time":0}
for i in range(len(A)+1):
  for j in range(len(B)+1):
    time = 0
    if i > 0:
    	time += sum(A[:i])
    if j > 0:
    	time += sum(B[:j])
    if time > K:
      break
    elif max < i+j:
      max = i+j
      memo["A"] = i
      memo["B"] = j
      memo["time"] = time
      
print(max) # , memo)

Submission status: Time Limit Exceeded

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

sum_A = [0, A[0]]
sum_B = [0, B[0]]

for a in A[1:]:
  sum_A.append(sum_A[-1] + a)

for b in B[1:]:
  sum_B.append(sum_B[-1] + b)

ans = 0
for i in range(N+1):
  for j in range(M+1):
    if sum_A[i] + sum_B[j] <= K:
      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()))
AS=[0]
BS=[0]
r=0
for i in A:
  AS.append(i+AS[-1])
for i in B:
  BS.append(i+BS[-1])
p=n+m+2
f=m+2
for i in range(1,n+2):
  for j in range(1,f):
    if AS[-i]+BS[-j]<=k:
      r=max(r,p-i-j)
      f=j
      break
print(r)

Submission status: Time Limit Exceeded

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=0
            break
an=max(an,lbk)

print(an)

Submission status: Time Limit Exceeded

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

# C - Tsundoku
def get_total_time(n):
	totals = [0] * (n + 1)
	arr = input().split()
	
	for i in range(n):
		totals[i + 1] = totals[i] + int(arr[i])
	
	return totals


n, m, k = map(int, input().split())
a_sum = get_total_time(n)
b_sum = get_total_time(m)
ans = 0

for i in range(n + 1):
	if a_sum[i] > k:
		break
	else:
		for j in range(m + 1):
			if a_sum[i] + b_sum[j] > k:
				break
			else:
				ans = max(ans, i + j)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import copy
L = list(map(int, input().split())) # N, M, K=map(int,input().split())
N=L[0]
M=L[1]
K=L[2]
A = list(map(int, input().split()))
B = list(map(int, input().split()))
P=[(0,0)]
R=[0]
c=0
while c!=N+M or Q!=[]:
    Q=[]
    S=[]
    c=c+1
    n=len(P)
    for i in range(n):
        a=P[i][0]
        b=P[i][1]
        if a<N and ((a+1,b) not in Q):
            C=R[i]+A[a]
            if C<=K:
                Q.append((a+1,b))
                S.append(C)
        if b<M  and ((a,b+1) not in Q):
            C=R[i]+B[b]
            if C<=K:
                Q.append((a,b+1))
                S.append(C)
    if Q!=[]:
        P=copy.copy(Q)
        R=copy.copy(S)
    else:
        c=c-1
        break
print(c)

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 = 1
while i < N:
    A[i] = A[i - 1] + A[i]
    i = i + 1
A.insert(0, 0)

i = 1
while i < M:
    B[i] = B[i - 1] + B[i]
    i = i + 1
B.insert(0, 0)

def sumsum(n, m):
    sum = A[n] + B[m]
    count = n + m
    return sum, count

n = 0
m = 0

sum_list = []
while n <= N:
    while m <= M:
        sum, count = sumsum(n, m)
        m = m + 1
        if sum <= K:
            sum_list.append([sum, count])
        else:
            break
    n = n + 1
    m = 0

print(max(sum_list)[1])

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 = 1
while i < N:
    A[i] = A[i - 1] + A[i]
    i = i + 1
A.insert(0, 0)

i = 1
while i < M:
    B[i] = B[i - 1] + B[i]
    i = i + 1
B.insert(0, 0)

def sumsum(n, m):
    sum = A[n] + B[m]
    count = n + m
    return sum, count


n = 0
m = 0

sum_list = []
while n <= N:
    while m <= M:
        sum, count = sumsum(n, m)
        m = m + 1
        if sum <= K:
            sum_list.append([sum, count])
    n = n + 1
    m = 0


print(max(sum_list)[1])

Submission status: Time Limit Exceeded

Solution code:
def sum_time(a, r_a):
  return sum(a[:r_a])

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

r_a = 0 # aの机の本を読む数
r_b = 0 # bの机の本を読む数

for r_a in range(0, n+1, 1):
  for r_b in range(0, m+1, 1):
    total_time = sum_time(a, r_a) + sum_time(b, r_b)
    if (total_time <= k):
      total_count = r_a + r_b

print(total_count)

Submission status: Time Limit Exceeded

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

for j in range(len(a_accum)):
  for i in range(len(b_accum)):
    t = a_accum[-(j+1)] + b_accum[-(i+1)]
    candi = (n-j) + (m-i)
    if ans >= candi:
      break
    if t <= k:
      ans = candi
      break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, m, v = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
i = 0
j = 0
x = 0
for i in range(n + 1):
  c = 0
  t = 0
  for j in range(i):
    if t + a[j] <= v:
      t += a[j]
      c += 1
    else:
      break
  for k in range(m):
    if t + b[k] <= v:
      t += b[k]
      c += 1
    else:
      break
  if x < c:
    x = c
  

print (x)

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

maxv = [0]
cnt = []
for i in range(n+1):
    maxv = sum(a[:i])
    idx = 0
    if maxv > k:
        cnt.append(i-1)
        break
    while idx < m and maxv <= k:
        maxv += b[idx]
        idx += 1
    if maxv > k:
        cnt.append(i + idx-1)
    else:
        cnt.append(i + idx)
print(max(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()))
a = [0] + a
b = [0] + b
l = []
aa = []

for i in range(n+1):
    if sum(a[0:i+1]) <= k:
        l.append(sum(a[0:i+1]))
        aa.append(i)
    for j in range(m+1):
        if sum(b[0:j+1]) <= k:
            l.append(sum(b[0:j+1]))
            aa.append(j)
        ans = sum(a[0:i+1]) + sum(b[0:j+1])
        if ans <= k:
            l.append(ans)
            aa.append(i+j)

print(max(aa))

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 HowManyBooks(A, B):
  A_sum, B_sum = [0], [0]
  for i in range(N):
    A_sum.append(A_sum[i] + A[i])
  for i in range(M):
    B_sum.append(B_sum[i] + B[i])
    books = 0
  for i in range(N+1):
    if A_sum[i] > K:
      break
    rest = K - A_sum[i]
    for j in range(M+1):
      if rest == B_sum[j]:
        books = max(books, i+j)
        break
      elif rest < B_sum[j]:
        books = max(books, i+j-1)
        break
    
  return books
print(HowManyBooks(A, B))

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.insert(0,0)
b.insert(0,0)

sum_a = [0]
for i in range(1,len(a)):
    sum_a.append(sum_a[i-1] + a[i])
    if sum_a[i] > k:
        break

sum_b = [0]
for i in range(1,len(b)):
    sum_b.append(sum_b[i-1] + b[i])
    if sum_b[i] > k:
        break

ans = 0
for i in range(len(sum_a)):
    if sum_a[i] > k:
        break
    for j in range(len(sum_b)-1,-1,-1):
        if sum_a[i] + sum_b[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.insert(0,0)
b.insert(0,0)

sum_a = [0]
for i in range(1,len(a)):
    sum_a.append(sum_a[i-1] + a[i])
    if sum_a[i] > k:
        break

sum_b = [0]
for i in range(1,len(b)):
    sum_b.append(sum_b[i-1] + b[i])
    if sum_b[i] > k:
        break

ans = 0
for i in range(len(sum_a)):
    if sum_a[i] > k:
        break
    for j in range(len(sum_b)-1,-1,-1):
        if sum_a[i] + sum_b[j] <= k:
            ans = max(ans, i+j)
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()))

sa = list(itertools.accumulate(a))
sb = list(itertools.accumulate(b))

max = 0

for i in range(n + 1):
    for j in range(m + 1):
        if (sa[i] + sb[j] <= k):
            if i + j > max:
                max = i + j 
        else:
            break
print(max)

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.insert(0,0)

ans = 0
time = 0
for i in range(len(a)):
    tmp = i
    time += a[i]
    if time > k:
        break
    tmp_time = time
    for j in range(len(b)):
        if tmp_time + b[j] <= k:
            tmp_time += b[j]
            tmp += 1
        else:
            break
    ans = max(ans,tmp)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect

def main():
    N, M, K = map(int, input().split())
    A = [int(v) for v in input().split()]
    B = [int(v) for v in input().split()]
    if N < M:
        for _ in range(M-N):
            A.append(0)
    else:
        for _ in range(N-M):
            B.append(0)
    C = [v1+v2 for v1, v2 in zip(A, B)]
    ruisekiA = [0 for _ in range(len(C)+1)]
    ruisekiB = [0 for _ in range(len(C)+1)]
    ruisekiC = [0 for _ in range(len(C)+1)]
    for i in range(len(C)):
        ruisekiA[i + 1] = ruisekiA[i] + A[i]
        ruisekiB[i + 1] = ruisekiB[i] + B[i]
        ruisekiC[i + 1] = ruisekiC[i] + C[i]

    ans = 0
    # i番目までは両方読む
    for i in range(min(N, M)+1):
        tans = i * 2
        tk = K - ruisekiC[i]
        if tk < 0:
            continue

        # A だけ、Bだけで何冊読めるか考える
        idx_a = bisect.bisect_left(ruisekiA[:N+1], tk + ruisekiA[i])
        if idx_a == len(ruisekiA) or ruisekiA[idx_a] != tk + ruisekiA[i]:
            idx_a -= 1
        idx_b = bisect.bisect_left(ruisekiB[:M+1], tk + ruisekiB[i])
        if idx_b == len(ruisekiB) or ruisekiB[idx_b] != tk + ruisekiB[i]:
            idx_b -= 1
        ans = max(ans, max(tans+idx_a-i, tans+idx_b-i))
    print(ans)


if __name__ == '__main__':
    main()

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

count = 0
j = 0
 
for i in range(N + M):
  if len(A) == 0 and len(B) == 0:
    count = N + M
  if len(A) == 0:
    j = B[0]
    del B[0]
  elif len(B) == 0:
    j = A[0]
    del A[0]
  elif A[0] <=  B[0]:
    j = A[0]
    del A[0]
  else:
    j = B[0]
    del B[0]
  if j <= K:
    K -= j
    count += 1
print(count)

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


count = 0
j = 0

for i in range(N + M):
  if len(A) == 0:
    j = B[0]
    del B[0]
  elif len(B) == 0:
    j = A[0]
    del A[0]
  elif A[0] <=  B[0]:
    j = A[0]
    del A[0]
  else:
    j = B[0]
    del B[0]
  if j <= K:
    K -= j
    count += 1
print(count)

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_A = [0]
for  i in range(N):
    sum_A.append(sum_A[i] + A[i])

sum_B = [0]
for  i in range(M):
    sum_B.append(sum_B[i] + B[i])

ans = 0
s = 0

for i in range (N + 1):
    for j in range(M + 1):
        s = sum_A[i] + sum_B[j]
        if s <= K:
            ans = max(ans, i + j)
        else:
            break

print(ans)