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


A = [0] +A

Bsum =[0]*M
sum =0

for i in range(len(B)):
    Bsum[i] = B[i]+sum
    sum = Bsum[i]

def binary_search_find_closest(data, target):
    
    if len(data) == 0:
        return None
    if len(data) == 1:
        return data[0]
    min_diff = float('inf')
    imin = 0
    imax = len(data) - 1
    closest_num = None
    while imin <= imax:
        imid = imin + (imax - imin) // 2
        #　中心の左右の値と目標との差を計算する。
        if imid + 1 < len(data):
            min_diff_right = abs(data[imid+1] - target)
        if imid > 0:
            min_diff_left = abs(data[imid-1] - target)
        # 最初の差と最も最小に近い値を更新する。
        if min_diff_left < min_diff:
            min_diff = min_diff_left
            closest_num = data[imid-1]
        if min_diff_right < min_diff:
            min_diff = min_diff_right
            closest_num = data[imid+1]
        # 2分探索する。
        if data[imid] < target:
            imin = imid + 1
        elif data[imid] > target:
            imax = imid -1
        else:
            return data[imid]
    return closest_num

# 15が表示される。

Atotal=0
Btotal=0
Aid=-1
Bid=0
total =0
cnt=0

for i in range(N+1):
    if A[i] >= 1000000000:
        break
    Atotal += A[i]
    Aid +=1
    if K - Atotal >=0:
        Btotal =binary_search_find_closest(Bsum,K - Atotal) 
        Bid = Bsum.index(Btotal)+1
        if Btotal >=1000000000:
            break
        if Atotal + Btotal > K:
            Btotal = Bsum[Bsum.index(Btotal)-1]
            Bid -=1
        total = Atotal+Btotal
        cnt = Aid +Bid


print(cnt)

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 = [0] +A

Bsum =[0]*M
sum =0

for i in range(len(B)):
    Bsum[i] = B[i]+sum
    sum = Bsum[i]

def binary_search_find_closest(data, target):
    
    if len(data) == 0:
        return None
    if len(data) == 1:
        return data[0]
    min_diff = float('inf')
    imin = 0
    imax = len(data) - 1
    closest_num = None
    while imin <= imax:
        imid = imin + (imax - imin) // 2
        #　中心の左右の値と目標との差を計算する。
        if imid + 1 < len(data):
            min_diff_right = abs(data[imid+1] - target)
        if imid > 0:
            min_diff_left = abs(data[imid-1] - target)
        # 最初の差と最も最小に近い値を更新する。
        if min_diff_left < min_diff:
            min_diff = min_diff_left
            closest_num = data[imid-1]
        if min_diff_right < min_diff:
            min_diff = min_diff_right
            closest_num = data[imid+1]
        # 2分探索する。
        if data[imid] < target:
            imin = imid + 1
        elif data[imid] > target:
            imax = imid -1
        else:
            return data[imid]
    return closest_num

# 15が表示される。

Atotal=0
Btotal=0
Aid=-1
Bid=0
total =0
cnt=0

for i in range(N+1):
    Atotal += A[i]
    Aid +=1
    if K - Atotal >=0:
        Btotal =binary_search_find_closest(Bsum,K - Atotal) 
        Bid = Bsum.index(Btotal)+1
        if Atotal + Btotal > K:
            Btotal = Bsum[Bsum.index(Btotal)-1]
            Bid -=1
        total = Atotal+Btotal
        cnt = Aid +Bid

print(cnt)

Submission status: Runtime Error

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


def solve(N, M, K, A, B) -> int:
    A.reverse()
    B.reverse()
    result = 0
    while True:
        print(K, A, B)
        if not A and not B:
            break
        elif not A and B:
            K -= B.pop()
        elif A and not B:
            K -= A.pop()
        elif A[-1] >= B[-1]:
            K -= B.pop()
        else:
            K -= A.pop()

        if K <= 0:
            break
        else:
            result += 1
    return result



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


A = [0] +A

Bsum =[0]*M
sum =0

for i in range(len(B)):
    Bsum[i] = B[i]+sum
    sum = Bsum[i]
    
print(Bsum)

def binary_search_find_closest(data, target):
    
    if len(data) == 0:
        return None
    if len(data) == 1:
        return data[0]
    min_diff = float('inf')
    imin = 0
    imax = len(data) - 1
    closest_num = None
    while imin <= imax:
        imid = imin + (imax - imin) // 2
        #　中心の左右の値と目標との差を計算する。
        if imid + 1 < len(data):
            min_diff_right = abs(data[imid+1] - target)
        if imid > 0:
            min_diff_left = abs(data[imid-1] - target)
        # 最初の差と最も最小に近い値を更新する。
        if min_diff_left < min_diff:
            min_diff = min_diff_left
            closest_num = data[imid-1]
        if min_diff_right < min_diff:
            min_diff = min_diff_right
            closest_num = data[imid+1]
        # 2分探索する。
        if data[imid] < target:
            imin = imid + 1
        elif data[imid] > target:
            imax = imid -1
        else:
            return data[imid]
    return closest_num

# 15が表示される。

Atotal=0
Btotal=0
Aid=-1
Bid=0
total =0
cnt=0

for i in range(N+1):
    Atotal += A[i]
    Aid +=1
    #print(Atotal)
    if K - Atotal >=0:
        Btotal =binary_search_find_closest(Bsum,K - Atotal) 
        Bid = Bsum.index(Btotal)+1
        if Atotal + Btotal > K:
            Btotal = Bsum[Bsum.index(Btotal)-1]
            Bid -=1
        total = Atotal+Btotal
        cnt = Aid +Bid
        #print(Atotal,Btotal,Aid,Bid)


print(cnt)

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, b = [0], [0]
for i in range(N):
    a.append(a[i] + A[i])
for i in range(M):
    b.append(b[i] + B[i])

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

Submission status: Runtime Error

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

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

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

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

Submission status: Runtime Error

Solution code:
def main():
    N,M,K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    
    indb = M-1
    now = sum(B)
    count = M
    while now > K:
        now -= B[indb]
        count -= 1
        indb -= 1
    
    ans = count
    
    for a in A:
        count += 1
        now += a
        
        while now >K and indb >= 0:
            now -= B[indb]
            count -= 1
            indb -= 1
        
        if now <= K:
            if ans < count:
                ans = count
    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()))
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)):
        sum_b += B[j]
        if sum_b > K - sum_a:
            ans = max(ans, i+j)
            break
        if j == len(B)-1:
            ans = max(ans, i+j+1)
print(ans)

Submission status: Runtime Error

Solution code:
import sys

INF = 10**9 + 5

N, M, K = map(int, sys.stdin.readline().rstrip().split())
A = [int(x) for x in sys.stdin.readline().rstrip().split()]
B = [int(x) for x in sys.stdin.readline().rstrip().split()]

A.append(INF)
A.append(INF)
i, j = 0, 0
t = 0
while i < N or j < M:

    if A[i] < B[j]:
        t += A[i]
        if t > K: break
        i += 1
    else:
        t += B[j]
        if t > K: break
        j += 1

print(i + j)

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
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)):
        sum_b += B[j]
        if sum_b > K - sum_a:#Bを全部読み切れない場合
            ans = max(ans, i+j)
            break
        if j == len(B)-1: #Bを全部読み切れる場合
            ans = max(ans, i+j+1)
print(ans)

Submission status: Runtime Error

Solution code:
n,m,k=map(int,input().split())
A=[0]+list(map(int,input().split()))
B=[0]+list(map(int,input().split()))
i=0
j=0
count=0
ans=0
for i in range(1,n+1):
  A[i]=A[i]+A[i-1]


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

a_cnt=0
b_cnt=m
for a_cnt in range(n+1):
  if A[a_cnt]>k:
    continue
  while A[a_cnt]+B[b_cnt]>k:
    b_cnt-=1 
  ans=max(ans,a_cnt+b_cnt)
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()))
ans = 0
sum_a = 0
for i in range(-1, len(A)):
    if i == -1:
        sum_a = 0
    else:
        sum_a += A[i]
        if sum_a > K:
            break
        sum_b = 0
    for j in range(len(B)):
        sum_b += B[j]
        if sum_b > K - sum_a:#Bを全部読み切れない場合
            ans = max(ans, i+1+j)
            break
        if j == len(B)-1: #Bを全部読み切れる場合
            ans = max(ans, i+j+2)
print(ans)

Submission status: Runtime Error

Solution code:
n,m,k=map(int,input().split())
A=[0]+list(map(int,input().split()))
B=[0]+list(map(int,input().split()))
i=0
j=0
count=0
ans=0
for i in range(1,n):
  A[i]=A[i]+A[i-1]


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

a_cnt=0
b_cnt=m
for a_cnt in range(n+1):
  if A[a_cnt]>k:
    continue
  #print('A',A[a_cnt])
  while A[a_cnt]+B[b_cnt]>k:
    #print('B',B[b_cnt+1])
    b_cnt-=1 
  ans=max(ans,a_cnt+b_cnt)
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()))
ans = 0
sum_a = 0
for i in range(-1, len(A)):
    if i == -1:
        sum_a = 0
    else:
        sum_a += A[i]
        if sum_a > K:
            break
        sum_b = 0
    for j in range(len(B)):
        sum_b += B[j]
        if sum_b > K - sum_a:#Bを全部読み切れない場合
            ans = max(ans, i+1+j)
            print("i = {0}, j = {1}, i+j +1 = {2}".format(i, j, i+j+1))
            break
        if j == len(B)-1: #Bを全部読み切れる場合
            ans = max(ans, i+j+2)
print(ans)

Submission status: Runtime Error

Solution code:
n,m,k=map(int,input().split())
A=[0]+list(map(int,input().split()))
B=[0]+list(map(int,input().split()))
i=0
j=0
count=0
ans=0
for i in range(1,n):
  A[i]=A[i]+A[i-1]


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


a_cnt=0
b_cnt=m
for a_cnt in range(n+1):
  if A[a_cnt]>k:
    continue
  #print('A',A[a_cnt])
  b_cnt=0
  while A[a_cnt]+B[b_cnt]>k:
    #print('B',B[b_cnt+1])
    b_cnt-=1 
  ans=max(ans,a_cnt+b_cnt)
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
import scipy.sparse as sps
import scipy.misc as spm
import collections as col
import functools as func
import itertools as ite
import fractions as frac
import math as ma
from math import cos,sin,tan,sqrt
import cmath as cma
import copy as cp
import sys
import re
import bisect as bs
sys.setrecursionlimit(10**7)
EPS = sys.float_info.epsilon
PI = np.pi; EXP = np.e; INF = np.inf
MOD = 10**9 + 7

def sinput(): return sys.stdin.readline().strip()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(n=0):
    if n: return [0 for _ in range(n)]
    else: return list(imap())
def farr(): return list(fmap())
def sarr(n=0):
    if n: return ["" for _ in range(n)]
    else: return sinput().split()
def adj(n): return [[] for _ in range(n)]

def meguru(ok, ng):
    while abs(ok - ng) > 1:
        mid = (ok + ng)//2
        if isOK(mid): ok = mid
        else: ng = mid
    return ok

def isOK(num): return bcum[num] <= tb

n,m,k = imap()
a,b = iarr(),iarr()
acum,bcum = np.array(a).cumsum(),np.array(b).cumsum()

anss = []
for i in range(n+1):
    ans = i + 1
    ta = 0 if i==n+1 else acum[i]
    if ta > k: continue
    else: tb = k - ta
    #ok,ng = -1,m
    #ans += meguru(ok,ng) + 1 # OKなければansは-1+1で不変
    ans += bs.bisect_right(bcum, tb)
    anss.append(ans)
ans = max(anss) if anss else 0
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()))
T = 0
p,q = 0,0
ret = 0
while True:
  if T > k:
    ret = p + q - 1
    break
  elif p == len(A) - 1 and q == len(B) - 1:
    ret = len(A) + len(B)
    break
  if A[p] > B[q]:
    if q < len(B):
    	T += B[q]
    	q += 1
    else:
      T += A[p]
      p += 1
  else:
    if p < len(A):
      T += A[p]
      p += 1
    else:
      T += B[q]
      q += 1
print(ret)

Submission status: Runtime Error

Solution code:
n,m,k = map(int,input().split())
a = map(int,input().split())
b = map(int,inpput().split())
ai= 0;bi=0
count =0
while k>0:
  min_ans = 1e9
  if a[ai]<b[bi]:
    min_ans = a[ai]
  else:
    min_ans = b[bi]
  if min_ans == a[ai]:
    ai+=1
  else:
    bi+=1
  if min_ans<=k:
    k-=min_ans
    count+=1
  else:
    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()))
T = 0
p,q = 0,0
ret = 0
while True:
  if T > k:
    ret = p + q - 1
    break
  elif p == len(A) - 1 and q == len(B) - 1:
    ret = len(A) + len(B)
    break
  if A[p] > B[q]:
    if q < len(B):
    	T += B[q]
    	q += 1
    else:
      T += A[p]
      p += 1
  else:
    if p < len(A):
      T += A[p]
      p += 1
    else:
      T += B[q]
      q += 1
print(ret)
n,m,k = map(int, input().split())
A,B, = list(),list()
for i in range(n):
  A.append(int(input))
for i in range(m):
  B.append(int(input))
T = 0
p,q = 0,0
ret = 0
while True:
  if T > k:
    ret = p + q + 1
    break
  elif p == len(A) - 1 and q == len(B) - 1:
    ret = len(A) + len(B)
    break
  if A[p] > B[q]:
    if q < len(B):
    	T += B[q]
    	q += 1
    else:
      T += A[p]
      p += 1
  else:
    if p < len(A):
      T += A[p]
      p += 1
    else:
      T += B[q]
      q += 1
print(ret)

Submission status: Runtime Error

Solution code:
n,m,k = map(int, input().split())
A,B, = list(),list()
for i in range(n):
  A.append(int(input))
for i in range(m):
  B.append(int(input))
T = 0
p,q = 0,0
ret = 0
while True:
  if T > k:
    ret = p + q + 1
    break
  elif p == len(A) - 1 and q == len(B) - 1:
    ret = len(A) + len(B)
    break
  if A[p] > B[q]:
    if q < len(B):
    	T += B[q]
    	q += 1
    else:
      T += A[p]
      p += 1
  else:
    if p < len(A):
      T += A[p]
      p += 1
    else:
      T += B[q]
      q += 1
print(ret)

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

x = [0]

y = [0]

for i in range(n):
    x.append(x[i]+a[i])

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

ans = 0

cnt = m

for i in range(n+1):
    
    if x[i]<0:
        break
    
    while y[cnt]>k-x[i]:
        cnt -= 1
        
    ans = max(ans,cnt+i)
    
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
divisors = [0] * N
ans = 0
for i in range(N):
    num = i+1
    for j in range(i, N, num):
        divisors[j] += 1
    ans += num * divisors[i]
print(ans)

Submission status: Runtime Error

Solution code:
from bisect import bisect_right


def main():
    n, m, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    for i in range(1, n):
        a[i] += a[i - 1]
    for i in range(1, m):
        b[i] += b[i - 1]
    answer = 0
    if a[-1] + b[-1] <= k:
        print(n + m)
    else:
        for i in range(n):
            l = bisect_right(b, k - a[i])
            if l == 0 or (l == m and b[l] + a[i] != k):
                continue
            answer = max(answer, i + 1 + l)
        print(answer)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys
import numpy as np
input = sys.stdin.readline

def main():
    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))
    Ac = np.append([0], np.cumsum(A))
    B = list(map(int, input().split()))
    Bc = np.append([0], np.cumsum(B))

    memo = [[-1] * int(M + 1) for _ in range(N + 1)]

    def dp(n, m):
        if Ac[n] + Bc[m] > K:
            return -1
        if memo[n][m] == -1:
            a, b = 0, 0
            if n < N:
                a = dp(n + 1, m) + 1
            if m < M:
                b = dp(n, m + 1) + 1
            memo[n][m] = max(a, b, 0)
        return memo[n][m]

    print(dp(0,0))

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from bisect import bisect_left


def main():
    n, m, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    for i in range(1, n):
        a[i] += a[i - 1]
    for i in range(1, m):
        b[i] += b[i - 1]
    answer = 0
    if a[-1] + b[-1] <= k:
        print(n + m)
    else:
        for i in range(n):
            l = bisect_left(b, k - a[i])
            diff = 1 if b[l] == k - a[i] else 0
            answer = max(answer, i + 1 + l + diff)
        print(answer)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

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

    memo = [[-1] * int(M + 1) for _ in range(N + 1)]

    def dp(n, m):
        if sum(A[:n]) + sum(B[:m]) > K:
            return -1
        if memo[n][m] == -1:
            a, b = 0, 0
            if n < N:
                a = dp(n + 1, m) + 1
            if m < M:
                b = dp(n, m + 1) + 1
            memo[n][m] = max(a, b, 0)
        return memo[n][m]

    print(dp(0,0))

if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

from itertools import accumulate
sum_a_list = list(accumulate([0] + a_list))
sum_b_list = list(accumulate([0] + b_list))

ans = 0
b_idx = 0
for a_idx in range(n+1):
    if sum_a_list[a_idx] > k:
        continue

    time_rest = k - sum_a_list[a_idx]
    b_idx = bisect.bisect_left(sum_b_list,time_rest)
    
    ans = max(ans, a_idx + b_idx)
        
print(ans)

Submission status: Runtime Error

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

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

    def dp(k, n, m):
        if k < 0:
            return -1

        a, b = 0, 0
        if n < N:
            a = dp(k - A[n], n + 1, m) + 1
        if m < M:
            b = dp(k - B[m], n, m + 1) + 1
        return max(a, b, 0)

    print(dp(K,0,0))

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()))
M = 0
a = 0
b = 0
while M <= 240:
    if A[a] < B[b]:
        M += A[a]
        a += 1
    else:
        M += B[b]
        b += 1
print(a+b)

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, b=[0], [0]
for　i　in　range(N):
  a.append(a[i]+A[i])
for　i　in　range(M):
  b.append(b[i]+B[i])
ans, j=0, M
for　i in range(N+1):
  if a[i]>K:
    break
  while b[j]>K-a[i]:
    j-=117ans=max(ans, i+j)
print(ans)

Submission status: Runtime Error

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

acum1=[0]

#それぞれの累積和(ai, bj)をもとめる
for i in range(n):
	acum1.append(acum[-1]+arr1[i])
    
acum2 = [0]

for i in range(m):
	acum2.append(acum2[-1]+arr2[i])

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

Submission status: Runtime Error

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

acum1=[0]

#それぞれの累積和(ai, bj)をもとめる
for i in range(n):
	# accum[-1]で一番最後のリストの値を参照している
    # うしろからみている
	acum1.append(acum[-1]+arr1[i])
    
acum2 = [0]

for i in range(m):
	# accum[-1]で一番最後のリストの値を参照している
    # うしろからみている
	acum2.append(acum2[-1]+arr2[i])

ans = 0
for i in range(n+1):
	# ai > K ->どのようにjを選んでもai+bj<=Kとなることはない
    # 探索を終了する
	if acum1[i] > k:
    	break
    #各iについて、bj<=K-aiを満たす最大のjを求める
    #bj>K-aiの間、ループ。jを大きい方から順に調べていく
    #限界ギリギリを調べるのだから、後ろから調べた方がよいという感じかな
    while acum2[j]>k - acum1[i] and j>0:
    	j -= 1
        ans = max(ans, i+j)
print(ans)

Submission status: Runtime Error

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

    a_sum = [0 for x in range(n)]
    b_sum = [0 for x in range(m)]

    a_sum[0] = a[0]
    b_sum[0] = b[0]

    max_counter = 0

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

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

    for i in range(n):
        for j in range(m):
            if k >= a_sum[i] + b_sum[j] and max_counter < i + j + 2:
                max_counter = i + j + 2
        
    print(max_counter)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
//C - Tsundoku
//Hiia
#include <stdio.h>
#include <stdlib.h>//rannsuu, zettaichi(absolute)
#include <time.h>
//srand((unsigned int) time(0));
#include <math.h>//koudona keisann
#include <string.h>//hairetsu
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
//#define N 998244353

int gcd(int m,int n){if((0==m)||(0==n))return 0;while(m!=n)if(m>n)m=m-n;else n=n-m;return m;}
int lcm(int m,int n){if((0==m)||(0==n))return 0;return(m*n/gcd(m, n));}
int fact(int x){if(x==1) return(x);else return(x*fact(x-1));}//Kaijou x!
int ruijou(int base,int exponent){int i,answer=1;i=exponent;while(i!=0){answer=answer*base;--i;}return answer;}//ruijou base^exponent

long long int llgcd(long long int m,long long int n){if((0==m)||(0==n))return 0;while(m!=n)if(m>n)m=m-n;else n=n-m;return m;}
long long int lllcm(long long int m,long long int n){if((0==m)||(0==n))return 0;return(m*n/llgcd(m, n));}
long long int llfact(long long int x){if(x==1) return(x);else return(x*llfact(x-1));}//Kaijou
int llruijou(long long int base,long long int exponent){long long int i,answer=1;i=exponent;while(i!=0){answer=answer*base;--i;}return answer;}//ruijou base^exponent

int main()
{
  long long int n,m,k,i,j,aa,num,ans;
  scanf("%lld %lld %lld", &n, &m, &k);
  long long int a[200010],b[200010];
  a[0] = b[0] = 0;
  for(i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
  }
  for(j = 1; j <= m; j++) {
    scanf("%lld", &b[j]);
  }
  aa=n+m;
  i=1;
  j=1;
  ans=0;
  while(num<=k){
    if(a[i]<=b[j] && i<=n && j<=m){
      num+=a[i];
      i++;
      ans++;
    }
    else if(a[i]>=b[j] && i<=n && j<=m){
      num+=b[j];
      j++;
      ans++;
    }
    else if(i==n+1 && j<=m){
      num+=b[j];
      j++;
      ans++;
    }
    else if(i<=n && j==m+1){
      num+=a[i];
      i++;
      ans++;
    }
    else if(i==n+1 && j==m+1){
      ans++;
      break;
    }
    else{
      ans++;
      printf("kono baai ha nai hazu\n");;
    }

  }
  //if(ans==aa+1){
  //  ans-=1;
  //}
  printf("%lld\n", ans-1);

  return 0;
}

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import itertools
from decimal import *

input = sys.stdin.readline

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
def inputStr(): return input()[:-1]

inf = float('inf')
mod = 1000000007

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

def main():
	N,M,K = inputMap()
	A = inputList()
	B = inputList()

	sumA = sum(A)
	sumB = sum(B)
	if sumA + sumB <= K:
		print(N+M)
		sys.exit()

		A.append(inf)
		B.append(inf)

	ans = 0
	times = 0

	while True:
		if times > K:
			break

		if A[0] < B[0]:
			times += A[0]
			A = A[1:]
		else:
			times += B[0]
			B = B[1:]
		#print(times)
		ans += 1

	print(ans-1)



#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
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()))
time=0
count=0
l=len(a)+len(b)
for i in range(l)
    if len(b)>0:
        if len(a)>0:
            if a[0]<b[0]:
                if time+a[0]<=k:
                    time+=a[0]
                    a.pop(0)
                else:
                    break
            else:
                if time+b[0]<=k:
                    time+=b[0]
                    b.pop(0)
                else:
                    break
        else:
            if time+b[0]<=k:
                time+=b[0]
                b.pop(0)
            else:
                break
    elif len(a)>0:
        if time+a[0]<=k:
            time+=a[0]
            a.pop(0)
        else:
            break
    else:
        break
    count+=1
print(count)

Submission status: Runtime Error

Solution code:
def sum_A(i, A):
  if i == 0:
    return 0
  return sum_A(i-1, A) + A[i-1]

def sum_B(j, B):
  if j == 0:
    return 0
  return sum_B(j-1, B) + B[j-1]  
  
def sum(i, j, A, B):##A[0]~A[i-1](i=0のときは読まない) B[0]~B[j-1](j=0のときは読まない)の合計値を計算する関数
   return sum_A(i, A) + sum_B(j, B)
  
n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
i = 0
count = 0
while i < n+1:
  j = 0
  while j < m+1:
    if sum(i, j, A, B) <= k and count < i + j:
      count = i + j 
    j +=1
  i +=1
  
print(count)

Submission status: Runtime Error

Solution code:
nums = [int(e) for e in input().split()]
N = nums[0]
M = nums[1]
K = nums[2]
A_mins = [int(e) for e in input().split()]
B_mins = [int(e) for e in input().split()]
count = 0
books = 0

for A in range(len(str(A_mins))):
    if count >= K:
        break
    else:
        pass
    if A <= N:
        count += A_mins[A]
        if count >= K:
            break
        else:
            books += 1
    for B in range(len(str(B_mins))):
        if count >= K:
            break
        else:
            pass
        if A_mins[A] < B_mins[B]:
            count += A_mins[A]
            if count >= K:
                break
            else:
                books += 1
                break
        else:
            count += B_mins[B]
            if count >= K:
                break
            else:
                books += 1

print (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()))
 
times = 0
buf = 0
a_i = 0
b_i = 0
count = 0
while times <= k:
  if a[a_i] < b[b_i]:
    times = times + a[a_i]
    buf = a[a_i]
    a_i = a_i + 1
    count = count + 1
  else:
    times = times + b[b_i]
    buf = b[b_i]
    b_i = b_i + 1
    count = count + 1 
   

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

times = 0
buf = 0
a_i = 0
b_i = 0
last_flag = 'a'
while times <= k:
  if a[a_i] < b[b_i]:
    times = times + a[a_i]
    a_i = a_i + 1
    buf = a[a_i]
  else:
    times = times + b[b_i]
    b_i = b_i + 1
    buf = b[b_i]

times = times - buf
print(times)

Submission status: Runtime Error

Solution code:

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


A_list.insert(0, 0)
B_list.insert(0, 0)
B_cumsum = np.cumsum(B_list)

time = B_cumsum[-1]
ans, j = 0, M

for i in range(N+1):
    if (time > K):
        break
    while (j > 0 and time > K):
        time -= B_list[j]
        j -= 1

    ans = max(ans, i+j)
    time += A_list[i]

print(ans)