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: Runtime Error

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

# k分で読める本の累積
a_ruiseki = [0]*(k+10)
b_ruiseki = [0]*(k+10)
a_cnt = 1
b_cnt = 1
a_sum = a[0]
b_sum = b[0]
for i in range(k+1):
    if a_sum == i and a_cnt < len(a)+1:
        a_cnt += 1
        tmp = min(a_cnt-1, len(a)-1)
        a_sum+=a[tmp]
    if b_sum == i and b_cnt < len(b)+1:
        b_cnt += 1
        tmp = min(a_cnt-1, len(a)-1)
        b_sum+=b[tmp]
    a_ruiseki[i] = a_cnt-1
    b_ruiseki[i] = b_cnt-1

#    print(f'{i} {a_cnt-1}')
#
#print(a_ruiseki)
#print(b_ruiseki)

ans = 0
for i in range(k+1):
    ans = max(ans, a_ruiseki[i]+b_ruiseki[k-i])
print(ans)

Submission status: Runtime Error

Solution code:
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
total = 0
ac = 0
bc = 0
count = 0
while True:
  if k < total:
    count -= 1
    break
  if bc < m:
    if ac < n and a[ac] <= b[bc]:
      total += a[ac]
      ac += 1
      count += 1
      continue
    else if a[ac] >= b[bc]:
      total += b[bc]
      bc += 1
      count += 1
      continue
  if ac < n:
    if bc < m and a[ac] >= b[bc]:
      total += b[bc]
      bc += 1
      count += 1
      continue
    else if a[ac] <= b[bc]:
      total += a[ac]
      ac += 1
      count += 1
      continue
  break
print(count)

Submission status: Runtime Error

Solution code:
n,m,k=map(int,input().split())
l1=list(map(int,input().split()))
l2=list(map(int,input().split()))
l3=[]
time=0
books=0
if n<=m:
    for i in range(n):
        if i%2==0:
            for j in range(n):
               l3.append(l1[j])
        else:
            for j in range(n):
              l3.append(l2[j])
    for x in range(n,m):
        l3.append(l2[x])
else:
    for i in range(m):
        if i%2==0:
            for j in range(m):
              l3.append(l2[j])
        else:
            for j in range(m):
              l3.append(l1[j])
    for i in range(m,n):
        l3.append(l1[i])
for i in range(n+m):
    if time > k or time > sum(l3) or l3[0]>k or l3[1]>k:
        break
    else:
        books+=1
        time+=l3[i]
print(books)

Submission status: Runtime Error

Solution code:
import sys

sys.setrecursionlimit(200000)

def whichDesk(a, b, i, j):
    if i < len(a) and j >= len(b):
        return 1
    elif j < len(b) and i >= len(a):
        return 2
    elif a[i] < b[j]:
        return 1
    elif a[i] > b[j]:
        return 2
    else:
        return whichDesk(a, b, i+1, j+1)

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

t = 0
cnt = 0

i = 0
j = 0

wd = 0

while t <= k and (i < len(a) or j < len(b)):
    wd = whichDesk(a, b, i, j)
    if wd == 2:
        t += b[j]
        j += 1
    else:
        t += a[i]
        i += 1

    if t <= k:
        cnt += 1
        
print(cnt)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(20000)

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

max_num = 0


def dfs(curr_a, curr_b, choice, time_required, count):
    global max_num
    if choice == 0:
        if curr_a >= N - 1:
            if max_num < count:
                max_num = count
            return
        else:
            curr_a += 1
            time_required += a[curr_a]
    else:
        if curr_b >= M - 1:
            if max_num < count:
                max_num = count
            return
        else:
            curr_b += 1
            time_required += b[curr_b]
    if time_required > K:
        return
    count += 1
    if max_num < count:
        max_num = count
    dfs(curr_a, curr_b, 0, time_required, count)
    dfs(curr_a, curr_b, 1, time_required, count)

curr_a = -1
curr_b = -1
time_required = 0
count = 0
dfs(curr_a, curr_b, 0, time_required, count)
curr_a = -1
curr_b = -1
time_required = 0
count = 0
dfs(curr_a, curr_b, 1, time_required, count)

print(max_num)

Submission status: Runtime Error

Solution code:
n,m,k = map(int,input().split());
alist = list(map(int,input().split()));
blist = list(map(int,input().split()));
asum = [0]*(n+1);
asum[1]=alist[0];
for p in range(1,n):
    asum[p+1] = asum[p]+alist[p];
bsum = [0]*(m+1);
bsum[1]=blist[0];
for q in range(1,m):
    bsum[q+1] = bsum[q]+blist[q]
    
    
print(asum);
print(bsum);

aa = 0;
bb = 0;
time = 0;

while True:
    if aa >= n and bb >= m:
        break;
    elif aa >= n:
        time = asum[n] + bsum[bb+1];
        if time >k:
            break;
        
        bb += 1;
    elif bb >= m:
        time = asum[aa+1] + bsum[m];
        if time > k:
            break;
        aa += 1
    else:
        a = asum[aa];
        b = bsum[bb];
        if a >= b:
            time = asum[aa] + asum[bb+1]
            if time > k:
                break;
            bb += 1
        else:
            time = asum[aa+1] + asum[bb]
            if time > k:
                break;
            aa += 1


print(aa+bb)

Submission status: Runtime Error

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

A_sum = 0
A_max = 0
B_sum = 0
B_max = 0
best_num = 0
A_max = N
flag = True
for i in range(N):
    A_sum += A[i]
    if A_sum > K:
        A_sum -= A[i]
        A_max = i
        flag = False
        break
A = A[0:A_max]
now_num = A_max
mixsum = A_sum
b_num = 0
if flag:
    for i in range(M):
        mixsum += B[i]
        if mixsum > K:
            mixsum -= B[i]
            now_num += i
            b_num = i
            break
A.reverse()
best_num = 0
for i in range(A_max):
    A_sum -= A[i]
    mixsum = A_sum
    now_num = A_max - i
    for j in range(M):
        mixsum += B[b_num+j]
        now_num += 1
        if mixsum > K:
            now_num -= 1
            break
    if now_num > best_num:
        best_num = now_num
print(best_num)

Submission status: Runtime Error

Solution code:
from collections import deque
N, M, K = map(int,input().split())
al = list(map(int,input().split()))
bl = list(map(int,input().split()))
al = deque(al)
bl = deque(bl)

time = 0
cnt = 0
for i in range(N+K):
    if len(al) >= 1 and len(bl) >= 1:
        if al[0] >= bl[0]:
            time += bl[0]
            if time > K:
                print(cnt)
                exit()
            else:
                bl.popleft()
                cnt += 1
        else:
            time += al[0]
            if time > K:
                print(cnt)
                exit()
            else:
                al.popleft()
                cnt += 1
    elif len(bl) == 0:
        time += al[0]
        if time > K:
            print(cnt)
            exit()
        else:
            al.popleft()
            cnt += 1
    elif len(al) == 0:
        time += bl[0]
        if time > K:
            print(cnt)
            exit()
        else:
            bl.popleft()
            cnt += 1
    else:
        print(cnt)
        break

Submission status: Runtime Error

Solution code:
a,b,c = map(int, input().split())
l1 = list(map(int, input().split()))
l2= list(map(int, input().split()))
i,j, s, d=0,0,0,0
while(s<c and (i<=(a-1) or j<=(b-1))):
    if((i<=(a-1))and l1[i]<l2[j]):
        if s+l1[i]<=c:
            s=s+l1[i]
            i=i+1
            d+=1
        else:
            break
    elif(j<=(b-1)):
        if (s+l2[j]<=c):
            s=s+l2[j]
            j=j+1
            d+=1
        else:
            break
print(d)

Submission status: Runtime Error

Solution code:
N = int(input())
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]
sum = 0
for i in range(N+1):
    sum += i * len(make_divisors(i))
print(sum)

Submission status: Runtime Error

Solution code:
n ,m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
while k > 0:
  i, j = 0
  if a[i] <= b[j]:
    k -= a[i]
    if k >= 0
      i += 1
      ans += 1
      if i >= n:
        for o in range(j, m):
          if k >= b[o]:
            k -= b[o]
            ans += 1
          else:
            k -= b[o]
            break
  else:
    k -= b[j]
    if k >= 0
      j += 1
      ans += 1
      if j >= m:
        for p in range(i, n):
          if k >= a[p]:
            k -= a[p]
            ans += 1
          else:
            k -= a[p]
            break
print(ans)

Submission status: Runtime Error

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

flag = True
que = list()
val = 0

def checkTundoku(index):
    flag = False
    a = b = val = -1
    if len(A) > index:
        a = A[index]
    if len(B) > index:
        b = B[index]
    if a < 0 and b < 0:
        return flag
    else:
        if a == b:
            checkTundoku(index+1)
        elif a < b:
            flag = 'A'
        else:
            flag = 'B'
    return flag

while flag:
    if checkTundoku(0) is False:
        flag = False
        break
    if checkTundoku(0) == 'A':
        val = A.pop(0)
    if checkTundoku(0) == 'B':
        val = B.pop(0)

    if sum(que) + val <= K:
        que.append(val)
    else:
        flag = False
        break

print(len([i for i in que if i > 0]))

Submission status: Runtime Error

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    n, m, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    ans = 0
    a_time = [0]
    b_time = [0]
    for i in range(1, len(a) + 1):
        a_time.append(a_time[i - 1] + a[i - 1])
    for i in range(1, len(b) + 1):
        b_time.append(b_time[i - 1] + b[i - 1])

    a_max = 0
    b_max = 0
    for i in range(len(a_time)):
        if a_time[i] > k:
            break
        else:
            a_max = i
    for i in range(len(b_time)):
        if b_time[i] > k:
            break
        else:
            b_max = i

    for i in range(len(b_time)):
        if a_time[a_max] + b_time[i] <= k:
            ans = max(ans, a_max + i)
        else:
            a_max -= 1
    for i in range(len(a_time)):
        if b_time[b_max] + a_time[i] <= k:
            ans = max(ans, b_max + i)
        else:
            b_max -= 1

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(2147483647)

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

def calc(k,i,j):
    c1 = 0
    c2 = 0
    global N,M,K,A,B
    if N-1>=i and A[i]+k <= K:
        c1 = 1+calc(A[i]+k,i+1,j)
    if M-1>=j and B[i]+k <= K:
        c2 = 1+calc(B[j]+k,i,j+1)
    return max(c1,c2)
count = calc(0,0,0)
print(count)

Submission status: Runtime Error

Solution code:
from collections import deque

n,m,k = map(int,input().split(" "))

a = deque(list(map(int,input().split())))
b = deque(list(map(int,input().split())))
cnt = 0
total = 0

while total+a[0] < k or total+b[0] < k:
    if len(a) > 0 and len(b) > 0:
        picked = min(a[0],b[0])
        if picked == a[0]:
            total += a.popleft()
            cnt += 1
        else:
            total += b.popleft()
            cnt += 1
    elif len(a) > 0 and len(b)==0:
        total +=a.popleft()
        cnt += 1
    elif len(b) > 0 and len(a)==0:
        total += b.popleft()
        cnt += 1
print(cnt)

Submission status: Runtime Error

Solution code:
"""everything has a cost!"""

from math import *
import random
import functools
import collections
import sys

__author__ = 'p7x'


# sys.stdin = open('in.txt', 'r')
# sys.stdout = open('out.txt', 'w')
# sys.stderr = open('err.txt', 'w')

n, m = 0, 0


# @functools.lru_cache(maxsize=None, typed=False)
def read(ti: int, tj: int, i: int, j: int) -> int:
    if (ti < n and (tj == m or a[ti] < b[tj])):
        return 1
    elif (tj < m and (ti == n or b[tj] < a[ti])):
        return 2
    elif (ti < n and tj < m):
        return read(ti+1, tj+1, i, j)
    else:
        if (ti == i and tj == j):
            return 3
        elif (ti == i):
            return 2
        else:
            return 1


if __name__ == '__main__':
    n, m, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))

    mins = 0
    i, j = 0, 0
    while (mins < k):
        v = read(i, j, i, j)
        # print(i, j, v)
        if (v == 1):
            mins += a[i]
            i += 1
        elif (v == 2):
            mins += b[j]
            j += 1
        else:
            break
    if mins > k:
        print(i+j-1)
    else:
        print(i+j)

Submission status: Runtime Error

Solution code:
from collections import deque

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

sum_minute = 0
ans = 0
while (sum_minute <= k) and (a or b):
    if a and b:
        if sum_minute + min(a[0], b[0]) <= k:
            if a[0] < b[0]:
                r = a.popleft()
                sum_minute += r
                ans += 1
            elif a[0] == b[0]:
                if a[1] <= b[1]:
                    r = a.popleft()
                    sum_minute += r
                    ans += 1
                else:
                    r = b.popleft()
                    sum_minute += r
                    ans += 1
            else:
                r = a.popleft()
                sum_minute += r
                ans += 1
        else:
            break
    elif not a:
        if sum_minute + b[0] <= k:
            r = b.popleft()
            sum_minute += r
            ans += 1
        else:
            break
    elif not b:
        if sum_minute + a[0] <= k:
            r = a.popleft()
            sum_minute += r
            ans += 1
        else:
            break

print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

N, M, K = list(map(int, input().split()))
A = list(map(int, [0] + input().split()))
B = list(map(int, [0] + input().split()))
cost = 0
ind_a = 0
ind_b = 0
dp = np.zeros((N + 3, M + 3)).astype(int)
cumsum_a = np.cumsum(A)
cumsum_b = np.cumsum(B)
max_book = 1
while True:
    for i in range(max_book + 1):
        if max_book - i <= N and i <= M:
            if K >= cumsum_a[max_book - i] + cumsum_b[i]:
                max_book += 1
                break
        else:
            continue
    else:
        break

print(max_book - 1)

Submission status: Runtime Error

Solution code:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
AB = sum(A) + sum(B)
a = N-1
b = M-1
x = len(A) + len(B)

while AB > K:
    if A[a]<B[b]:
        AB -= B[b]
        b -= 1
        x -= 1
    else:
        AB -= A[a]
        a-=1
        x -= 1

print(x+1)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

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

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

for l in range(N+M+1):
    min_time_l = min(
        [sum_A[i]+sum_B[l-i] 
        for i in range(max(l-M,0), N+1)])
    if min_time_l > K:
        print(l-1)
        exit(0)

print(N+M)

Submission status: Runtime Error

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

j = 0
ans = 0

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

Submission status: Runtime Error

Solution code:
import numpy as np
N, M, K = map(np.int64, input().split())
A = list(map(np.int64, input().split()))
B = list(map(np.int64, input().split()))

time0 = 0
cnt = 0
while(time0<=K):
    if len(A) == 0 and len(B) != 0:
        time0 += B.pop(0)
        cnt += 1
    elif len(B) == 0 and len(A) != 0:
        time0 += A.pop(0)
        cnt += 1
    elif len(A) == 0 and len(B) == 0:
        cnt += 1
        break
    else:
        if A[0] < B[0]:
            time0 += A.pop(0)
            cnt += 1
        elif A[0] > B[0]:
            time0 += B.pop(0)
            cnt += 1
        else:
            if A[1]<=B[1]:
                time0 += A.pop(0)
                cnt+=1
            else:
                time0 += B.pop(0)
                cnt+=1
            
cnt -= 1

print(cnt)

Submission status: Runtime Error

Solution code:
A=[]
B=[]
books = 0
time = 0
n, m, k = map(int,input().split())
i = n-1
j = m - 1
A = list(map(int,input().strip().split()))[:n] 
B = list(map(int,input().strip().split()))[:m] 
# A =  map(int,input().split())
# B =  map(int,input().split())
# for i in range(0,n):
#     A.append(int(input()))
# for i in range(0,m):
#     B.append(int(input()))
while not(time > k) :
    if (i> -1 and j> -1 and A[i]<B[j]) or (i>-1 and not(j>-1)):
        time = time+A[i]
        i=i-1
        books=books+1
    elif (i> -1 and j> -1 and not(A[i]<B[j])) or (j>-1 and not(i>-1)):
            time = time+A[i]
            i=i-1
            books=books+1
print(books)

Submission status: Runtime Error

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

if sum(A) + sum(B) <= K:
    print(len(A) + len(B))
elif K < min(A) and K < min(B):
    print(0)

else:
    books = []
    for i in range(N):
        a_num = i+1
        a_time = sum(A[0:a_num+1])
        b_time = 0
        for j in range(M):
            if a_time + b_time + B[j] > K and a_time + b_time < K:
                books.append( i + j + 2)
                break
            b_time += B[j]

   
    print(max(books))

Submission status: Runtime Error

Solution code:
N,M,K = map(int,input().split())
A =list(map(int,input().split()))
B =list(map(int,input().split()))
C = A+B
a = 0
b = 0
min = 0
cnt= 0

if sum(C) <= K:
  print(len(C))
else:
  while min <= K:
    if  len(A) >a and A[a] <= B[b]:
      min += A[a]
      a +=1
      cnt +=1
    elif len(B) >b and A[a] > B[b]:
      min +=B[b]
      b +=1
      cnt+=1
    elif len(A) <= a:
      min +=B[b]
      b +=1
      cnt+=1
    elif len(B) <= b:
      min +=A[a]
      a += 1
      cnt+=1
  print(cnt-1)

Submission status: Runtime Error

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

time = 0
count = 0
while len(a) > 0 or len(b) > 0:
    if len(a) ==  0:
        book_b = b.popleft()
        time += book_b
        count += 1
    elif len(b) == 0:
        book_a = a.popleft()
        time += book_a
        count+= 1
    elif a[0] > b[0]:
        book_b = b.popleft()
        time += book_b
        count += 1
    elif a[0] == b[0]:
        if a[1] > b[1]:
            book_b = b.popleft()
            time += book_b
            count += 1
        else:
            book_a = a.popleft()
            time += book_a
            count += 1            
    else:
        book_a = a.popleft()
        time += book_a
        count += 1
    if time > k:
        count -= 1
        break

    
print(count)

Submission status: Runtime Error

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

ans=0
for n in range(N+M):
    if A[0]<=B[0]:
        if K-A[0]>=0:
            K=K-A[0]
            if len(A)==1:
                A[0]=0
                ans+=1
            else:
                del A[0]
                ans+=1
        else:
            break
    else:
        if K-B[0]>=0:
            K=K-B[0]
            if len(A)==1:
                B[0]=0
                ans+=1
            else:
                del B[0]
                ans+=1
        else:
            break
            
print(ans)

Submission status: Runtime Error

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

ans = 0
def dfs(a, b, k):
	global ans

	if a == (N - 1) and b == (M - 1):
		return True

	if k < 0:
		return False

	if a < N and k >= A[a] and dfs(a + 1, b, k - A[a]):
		ans += 1
		return True

	if b < M and k >= B[b] and dfs(a, b + 1, k - B[b]):
		ans += 1
		return True

	return True

dfs(0, 0, K)
print(ans)

Submission status: Runtime Error

Solution code:
import bisect

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()]
sum_a=[a[0]]
for i in range(len(a)-1):
    sum_a.append(sum_a[i]+a[i+1])
sum_b=[b[0]]
for i in range(len(b)-1):
    sum_b.append(sum_b[i]+b[i+1])

#現在のインデックス
idx_a=0
idx_b=0

while idx_a<n or idx_b<m:
    read=''
    #aの読める数
    oset_a=sum_a[idx_a-1] if idx_a>0 else 0
    can_cnt_a=bisect.bisect_right(sum_a,k+oset_a)
    #bの読める数
    oset_b=sum_b[idx_b-1] if idx_b>0 else 0
    can_cnt_b=bisect.bisect_right(sum_b,k+oset_b)
    read='a' if can_cnt_a-idx_a>=can_cnt_b-idx_b else 'b'
    

    #読むほうをPOP
    k-=a[idx_a] if read=='a' else b[idx_b]
    #kを超えた場合ブレーク
    if k<0:
        break
    #カウントアップ
    if read=='a':
        idx_a+=1
    else:
        idx_b+=1
print(idx_a+idx_b)

Submission status: Runtime Error

Solution code:
from sys import stdin, stdout
import heapq
import cProfile
from collections import Counter, defaultdict, deque
from functools import reduce
import math
from bisect import bisect, bisect_right, bisect_left


def get_int():
    return int(stdin.readline().strip())


def get_tuple():
    return map(int, stdin.readline().split())


def get_list():
    return list(map(int, stdin.readline().split()))

save = 0
def fun(n, m, k, ans):
    global mx, a, b, dp,save

    mx = max(mx, ans)

    if n <= 0 and m <= 0 or k <= 0:
        return ans

    # key = str(n)+"_"+str(m)+"_"+str(k)
    # if key in dic:
    #     save += 1
    #     return dic[key]

    x, y = -100, -100
    if n > 0 and a[n - 1] <= k:
        x = fun(n - 1, m, k - a[n - 1], ans + 1)
    if m > 0 and b[m - 1] <= k:
        y = fun(n, m - 1, k - b[m - 1], ans + 1)
    # dic[key] = max(x,y)
    return max(x, y)


mx = 0
n, m, k = get_tuple()
dic = defaultdict(int)
a = get_list()
b = get_list()
a = a[::-1]
b = b[::-1]
fun(n, m, k, 0)
print(mx)

Submission status: Runtime Error

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

A_ruiseki = []
if A[0]<=k:
    A_ruiseki.append(A[0])
    for i in range(1, n):
        if A_ruiseki[i-1]+A[i] <= k :
            A_ruiseki.append(A_ruiseki[i-1]+A[i])
        else:
            break

B_ruiseki = []
if B[0]<=k:

    B_ruiseki.append(B[0])
    for i in range(1, n):
        if B_ruiseki[i-1]+B[i] <= k :
            B_ruiseki.append(B_ruiseki[i-1]+B[i])
        else:
            break

ans = len(A_ruiseki)

for i in range(len(A_ruiseki)):
    time = A_ruiseki[i]
    expected = max(ans-i-2, 0)

    if len(B_ruiseki) <= expected:
        continue
    if time + B_ruiseki[expected] > k:
        continue
    if expected > 0:
        time += B_ruiseki[expected-1]
    for j in range(expected, len(B)):

        if time + B[j] > k:
            break

        time += B[j]

        ans =i+2+j

print(ans)

Submission status: Runtime Error

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


def log(*args):
    print(*args, file=sys.stderr)


def main():
    _n, _m, k = map(int, input().split())
    ns = list(map(int, input().rstrip().split()))
    ms = list(map(int, input().rstrip().split()))
    sum = 0
    count = 0
    for v in ns:
        if sum + v > k:
            break
        else:
            sum += v
            count += 1

    ans_now = count
    ans = ans_now
    i = count - 1
    for v in ms:
        if sum + v > k:
            while sum + v > k:
                sum -= ns[i]
                i -= 1
                ans_now -= 1
                if i < 0:
                    break
            if sum + v > k:
                break
            sum += v
            ans_now += 1
        else:
            sum += v
            ans_now += 1
        ans = max(ans, ans_now)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
c = 0
t = 0
ac = 0
bc = 0

for i in range(N + M):
  if A[ac] > B[bc]:
    K -= B[bc]
    bc += 1
  elif A[ac] < B[bc]:
    K -= A[ac]
    ac += 1
  elif A[ac] == B[bc]:
    K -= A[ac]
    ac += 1
  if  K >= 0:
    c += 1
  else:
    break
print(c)

Submission status: Runtime Error

Solution code:
import sys

n, m, k = map(int, input().split())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))

ans = []

def hoge(z, c, a, b):
    # 終了条件
    if ((len(a) == 0) and (len(b) == 0)) or (z > k):
        ans.append(c)
        return

    # aから
    if len(a) == 0:
        z += b.pop(0)

    # bから
    elif (len(b) == 0) or (a == b):
        z += a.pop(0)

    # a,b　同じ
    elif a[0] == b[0]:
        a_sub = a[:]
        z_a = z + a_sub.pop(0)
        if z_a <= k:
            c_a = c + 1
        else:
            c_a = c
        b_sub = b[:]
        z_b = z + b_sub.pop(0)
        if z_b <= k:
            c_b = c + 1
        else:
            c_b = c
        return hoge(z_a, c_a, a_sub, b), hoge(z_b, c_b, a, b_sub)
    else:
        if a[0] > b[0]:
            z += b.pop(0)
        else:
            z += a.pop(0)

    if z <= k:
        c += 1


    return hoge(z, c, a, b)

hoge(0, 0, a_list, b_list)
print(max(ans))

Submission status: Runtime Error

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

def csum(l,ll):
    s = 0
    res = [0] * ll
    for i in range(ll):
        s += l[i]
        res[i] = s
    return res

csln = csum(ln,n)
cslm = csum(lm,m)

import numpy as np

lk = [k-x for x in csln if k-x >=0]
res = np.searchsorted(np.array(cslm), np.array(lk), side='right').
rmax = 0
for i,j in zip(range(1,len(lk)+1), res):
    rmax = max(rmax, i+j)
print(int(rmax))

Submission status: Runtime Error

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

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

      #print(tmpst)
      tmpc += 1
      #print(tmpai, tmpbi)
print(c)

Submission status: Runtime Error

Solution code:
A=[]
B=[]
books = 0
time = 0
n, m, k = map(int,input().split())
i = n-1
j = m - 1
A = list(map(int,input().strip().split()))[:n] 
B = list(map(int,input().strip().split()))[:m] 
while not(time > k) :
    if (i> -1 and j> -1 and A[i]<B[j]) or (i>-1 and not(j>-1)):
        time = time+A[i]
        i=i-1
        books=books+1
    elif (i> -1 and j> -1 and not(A[i]<B[j])) or (j>-1 and not(i>-1)):
            time = time+A[i]
            i=i-1
            books=books+1
print(books)

Submission status: Runtime Error

Solution code:
import numpy as np

n, m, k = [int(e) for e in input().split()]
a = np.array([int(e) for e in input().split()])
b = np.array([int(e) for e in input().split()])

asum = a.cumsum()
bsum = b.cumsum()

#aのみbのみ
onlya = (asum < k).sum()
onlyb = (bsum < k).sum()
ans = max(onlya,onlyb)

xs,ys = np.meshgrid(asum,bsum)
nums = list(zip(*np.where(xs+ys < k)))
for i in nums:
    if i[0]+i[1]+2 > ans:
        ans = i[0]+i[1]+2

print(ans)