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()))
s=0
while(len(A)>0 and len(B)>0 and K>=0):
    if A[0]<=B[0]:
        K-=A[0]
        s+=1
        A.pop(0)
    else:
        K-=B[0]
        s+=1
        B.pop(0)
if K<0:
    print(s-1)
elif K=0:
    print(s)
else:
    if len(A)==0:
        while(len(B)>0 and K>=0):
            K-=B[0]
            s+=1
            B.pop(0)
        if K<0:
            print(s-1)
        else:
            print(s)
    else:
        while(len(A)>0 and K>=0):
            K-=A[0]
            s+=1
            A.pop(0)
        if K<0:
            print(s-1)
        else:
            print(s)

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
count=0
while c+min(a[0],b[0])<=k:
  
 c+=min(a[0],b[0])
 count+=1
 if min(a[0],b[0])==a[0]:
   a.remove(a[0])
 else:
   b.remove(b[0])         
print(count)

Submission status: Runtime Error

Solution code:
#!/usr/bin/python3
# import bisect
# from collections import Counter, deque, OrderedDict, defaultdict
# from copy import copy, deepcopy # pythonのみ．copyは1次元，deepcopyは多次元．
# from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
# from functools import reduce
# from heapq import heapify, heappop, heappush
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import statistics # Pythonのみ
# import string
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

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

    from itertools import accumulate
    
    
    AA = [0] + A
    BB=[0]+B
    # 累積和を格納したリスト．A[l:r]の総和はB[r] - B[l]
    AA = list(accumulate(A))
    BB=list(accumulate(B))

    ans=0
    v=0
    for i in range(n+1):
        for j in range(v,m+1):
            if AA[i]+BB[j]<=k:
                ans=max(ans,i+j)
            else:
                v=j-1
                break
    print(ans)

    
resolve()

Submission status: Runtime Error

Solution code:

def appendd(N, A, sumlis, lis, K):
    for a in range(N):
        if A[a]+sumlis > K:
            if lis[-1] > A[a]:
                sumlis += A[a] - lis[-1]
                lis[-1] = A[a]
                lis.sort()
        else :
            lis.append(A[a])
            lis.sort()
            sumlis += A[a]
    return sumlis, lis


def func():
    N,M,K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    sumlis = 0
    lis =[]
    
    sumlis, lis = appendd(N, A, sumlis,lis,K)
    _,     lis = appendd(M, B, sumlis,lis,K)
    print(len(lis))
if __name__=='__main__':
    func()

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
i = 0
j = 0
if(K-A[0] > 0 or K-B[0] > 0):
    while(K >= 0):
        if(A[i] <= B[j]):
            K -= A[i]
            i += 1
            time += 1
            if(i == len(A)):
                A.append(10000000000)
        if(A[i] >=B[j]):
            K -= B[i]
            j += 1
            time += 1
            if(j == len(B)):
                B.append(10000000000)
    print(time)
else:
    print(0)

Submission status: Runtime Error

Solution code:
n,m,k = map(int,input().split())
a = list(map(int,input().split()))+[10**9+1]*m
b = list(map(int,input().split()))+[10**9+1]*n
Sum = 0
ans = 0
a_i = 0
b_i = 0
N = n+m

for i in range(N):
    if a[a_i] < b[b_i]:
        Sum += a[a_i]
        a_i += 1
    elif a[a_i] > b[b_i]:
        Sum += b[b_i]
        b_i += 1
    else:
        flag = True
        for j in range(N-i+1):
            if a[a_i+j] < b[b_i+j]:
                Sum += a[a_i]
                a_i += 1
                break
            elif a[a_i+j] > b[b_i+j]:
                Sum += b[b_i]
                b_i += 1
                break
    if Sum > k:
        ans = i
        break
else:
    ans = N

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=0
while sum<=k and (A!=[] or B!=[]):
    if A!=[] and B!=[]:
        a=A[0]
        b=B[0]
        if a<b or B==[]:
            sum+=A.pop(0)
            ans+=1
        elif b<a and A==[]:
            sum+=B.pop(0)
            ans += 1
        else:
            x=min(len(A),len(B))
            for i in range(x):
                if A[i]<B[i]:
                    sum += A.pop(0)
                    ans += 1
                    break
                elif A[i]>B[i]:
                    sum += B.pop(0)
                    ans += 1
                    break
            if len(A)>len(B):
                if A[i+1]>B[i]:
                    sum += B.pop(0)
                    ans += 1
                else:
                    sum += A.pop(0)
                    ans += 1
    elif A!=[]:
        sum += A.pop(0)
        ans += 1
    elif B!=[]:
        sum += B.pop(0)
        ans += 1
if sum>k:
    print(ans-1)
else:
    print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

N, M, K = map(int, input().split())
A = [int(n) for n in input().split()]
B = [int(n) for n in input().split()]

A = np.array(A)
B = np.array(B)

A = np.cumsum(A)
B = np.cumsum(B)

A1 = np.zeros((len(A),2))
A1[:,0] = A
A1[:,1] = np.arange(1,len(A)+1)

B1 = np.zeros((len(B),2))
B1[:,0] = B
B1[:,1] = np.arange(1,len(B)+1)

C1 = np.zeros((len(A)*len(B),2))
lenB = len(B)
for i in range(len(A)):
    for j in range(len(B)):
        C1[lenB*i+j,:] = A1[i,:] + B1[j,:]
C2 = np.array([[Cl[0],Cl[1]] for Cl in C1 if Cl[0] <= K])
print(int(C2[:,1].max()))

Submission status: Runtime Error

Solution code:
N, M, K= map(int, input().split())
li = list(map(int, input().split()))
li2 = list(map(int, input().split()))
a = 0
b = 0
c = 0
count= 0
while True:
    if a < N and b < M:
        if li[a] <= li2[b] and c + li[a] <= K:
            c += li[a]
            a += 1
            count += 1
        elif li[a] >= li2[b] and c + li2[b] <= K:
            c += li2[b]
            b += 1
            count += 1
        else:
            break
    elif a < N:
        if c + li[a] <= K:
            c += li[a]
            a += 1
            cnout += 1
        else:
            break
    elif b < M:
        if c + li2[b] <= K:
            c += li2[b]
            b += 1
            count += 1
        else:
            break
    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()))

a_i= 0
b_i= 0
f = True

if sum(a)+sum(b) <= k:
    print(n+m)
    exit()

for i in range(n+m):
    # print(a_i,b_i,k)
    if a[a_i] < b[b_i]:
        k -= a[a_i]
        if k < 0:
            break 
        a_i += 1
        if a_i == n:
            for j in range(m):
                if k < 0:
                    break
                k -= b[b_i]
                b_i += 1
    else:
        k -= b[b_i]
        if k < 0:
            break 
        b_i += 1
        if b_i == m:
            for j in range(n):
                if k < 0:
                    break
                k -= a[a_i]
                a_i += 1
    

    

print(a_i+b_i)

Submission status: Runtime Error

Solution code:
N,M,K=list(map(int, input().split()))
res=0
ans=0
A=list(map(int, input().split()))
B=list(map(int, input().split()))
pa=pb=0
while not (pa==N and pb==M):
    if pa==N:
        a=B[pb]
        pb += 1
    elif pb==N:
        a=A[pa]
        pa += 1
    else:
        a=min(A[pa],B[pb])
        if a==A[pa]:
            pa+=1
        else:
            pb+=1
    res+=a
    if res>K:
        break
    else:
        ans+=1
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()))

numA = 0
numB = 0
count = 0
time = 0
for i in range(N+M):
  if numA < N and numB < M:
    if A[numA] > B[numB] and time + B[numB] <= K:
      count += 1
      time += B[numB]
      numB += 1
    elif A[numA] < B[numB] and time + A[numA] <= K:
      count += 1
      time += A[numA]
      numA += 1
    elif A[numA] == B[numB]:
      if numA == N-1 and time + B[numB] <= K:
        count += 1
        time += B[numB]
        numB += 1
      elif numB == M-1 and time + A[numA] <= K:
        count += 1
        time += A[numA]
        numA += 1
      elif A[numA + 1] > B[numB + 1] and time + B[numB] <= K:
        count += 1
        time += B[numB]
        numB += 1        
      elif A[numA + 1] <= B[numB + 1] and time + A[numA] <= K:    
        count += 1
        time += A[numA]
        numA += 1    
      else:
        break
    else:
      break
  else:
    if numA >= N and numB < M and time + B[numB] <= K:
      count += 1
      time += B[numB]
      numB += 1
    elif numB >= M and numA < N and time + A[numA] <= K:
      count += 1
      time += A[numA]
      numA += 1
    else:
      break
print(count)

Submission status: Runtime Error

Solution code:
import numpy as np
M,N,K = [int(hoge) for hoge in input().split()]
A = [int(hoge) for hoge in input().split()]
B = [int(hoge) for hoge in input().split()]
S = 0
Abook = 0
Bbook = 0
curbook = 0
for a in A:
    if S + a <= K:
        Abook += 1
        curbook += 1
        S += a
nextB = 0
for n,b in enumerate(B):
    if S + b <= K:
        Bbook += 1
        curbook += 1
        S += b
    else:
        nextB = n
        break
ans = curbook

for i in range(Abook):
    Abook -= 1
    curbook -= 1
    S -= A[Abook]
    for b_index in range(nextB,len(B)):
        if S + B[b_index] <= K:
            Bbook += 1
            curbook += 1
            S += B[b_index]
        else:
            nextB = b_index
            break
    ans = max(ans,curbook)
print(ans)

Submission status: Runtime Error

Solution code:
from sys import stdin
from itertools import accumulate

n, m, k = [int(x) for x in stdin.readline().rstrip().split()]
a = [int(x) for x in stdin.readline().rstrip().split()]
b = [int(x) for x in stdin.readline().rstrip().split()]

goukei = 0
new = []
for i in range(n + m):
  if len(a) == 0:
    new.append(b[0])
    b.pop(0)
  elif len(b) == 0:
    new.append(a[0])
    a.pop(o)
  elif a[0] <= b[0]:
    new.append(a[0])
    a.pop(0)
  elif a[0] > b[0]:
    new.append(b[0])
    b.pop(0)

new = list(accumulate(new))
for x in range(len(new)):
  if new[x] <= k:
    goukei += 1

print(goukei)

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_max = 0
A_count = 0
B_count = 0

P = K

for i in range (0, N):
	if A[i] < P:
		A_count+=1
		P = P-A[i]
	else:
 		break

for j in range (0, M):
	if B[i] < P:
		B_count+=1
		P = P-B[i]
	else:
 		break

totalmax = A_count+B_count

for i in range (0, A_count):
	D = P + A[A_count-1-i]
	E = D
	zencount = A_count-(i+1)
	for j in range (0, M):
		if B[j] < E:
			E-=B[j]
			zencount+=1
		else:
			break
	if zencount >= totalmax:
		totalmax = zencount

print(totalmax)

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
while K > 0:
    if not A == [] and not B == []:
        if A[0] >= B[0]:
            K = K - A[0]
            A.remove(A[0])
            if K >= 0:
                c += 1
        else:
            K = K - B[0]
            B.remove(B[0])
            if K >= 0:
                c += 1
    if A == []:
        K = K - B[0]
        B.remove(B[0])
        if K >= 0:
            c += 1
    if B == []:
        K = K - A[0]
        A.remove(A[0])
        if K >= 0:
            c += 1
print(c)

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

count = 0
sum = 0
while 1:
    if n  == 0 and m == 0:
        break
    elif n == 0:
        tmp = b.pop(0)
        m -= 1
    elif m == 0:
        tmp = a.pop(0)
        n -= 1
    elif a[0] > b[0]:
        tmp = b.pop(0)
        m -= 1
    elif a[0] < b[0]:
        tmp = a.pop(0)
        n -= 1

    print(n, m, sum)
    sum += tmp
    if sum  > k:
        break
    count += 1
print(count)

Submission status: Runtime Error

Solution code:
from collections import deque

n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
Q = deque([[0, 0, 0]])
ans = 0
if sum(A) + sum(B) <= k:
    print(n+m)
else:
    while len(Q) > 0:
        a, b, t = Q.popleft()
        print([a, b, t])
        if a < n:
            t1 = t + A[a]
            a1 = a + 1
            if t1 <= k:
                if [a1, b, t1] in Q:
                    pass
                else:
                    Q.append([a1, b, t1])
            else:
                ans = max(ans, a+b)
        else:
            pass
        if b < n:
            t2 = t + B[b]
            b2 = b + 1
            if t2 <= k:
                if [a, b2, t2] in Q:
                    pass
                else:
                    Q.append([a, b2, t2])
            else:
                ans = max(ans, a+b)
        else:
            pass
        print(Q)
    print(ans)

Submission status: Runtime Error

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

if __name__ == '__main__':
  n,m,k=map(int,input().strip("\n").split())
  A=list(map(int,input().strip("\n").split()))
  B=list(map(int,input().strip("\n").split()))

  def dfs(a,b,k,s):
    if k<0:
      return s-1
    if k==0:
      return s
    if a!=n:
      ansA=dfs(a+1,b,k-A[a],s+1)
    else:
      ansA=s
    if b!=m:
      ansB=dfs(a,b+1,k-B[b],s+1)
    else:
      ansB=s
    return max(ansA,ansB)

  ans=dfs(0,0,k,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()))
while i<N or j<M:
    if i==N:
        i=N-1
    if j==M:
        j=M-1
    if A[i]>=B[j]:
        ans=ans+B[j]
        j=j+1
        if ans>K:
            print(i+j-1)
            break
    else:
        ans=ans+A[i]
        i=i+1
        if ans>K:
            print(i+j-1)
            break

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()))
#print(N,M,K)
#print(A)
#print(B)
i=0
j=0
cnt=0
time=0
if sum(A)+sum(B)<=K:
    cnt = len(A)+len(B)
elif A[0]>K and B[0]>K:
    cnt = 0
else:
    for n in range(200000):
        if A[i]<=B[j]:
            
            time = time+A[i]
            i = i+1
            if time>K:
                break
            else:
                cnt=cnt+1
        elif A[i]>B[j]:
            time = time+B[j]
            j = j+1
            if time>K:
                break
            else:
                cnt=cnt+1
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.sort()
b.sort()
# print(a,b)

time = 0
ia = 0
ib = 0

while time <= k:
    if ia >= len(a):
        time += b[ib]
        ib += 1
    elif ib >= len(b):
        time += a[ia]
        ia += 1
    elif a[ia] <= b[ib]:
        time += a[ia]
        ia += 1
    else:
        time += b[ib]
        ib += 1

if time > k:
    print(ia + ib - 1)
else:
    print(ia + ib)

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_b = 0
count = 0

for i in range(m):
    if k < sum_b + b[i]:
        break
    sum_b += b[i]
    count += 1

ans = count
sum_a = 0
count = 0

for i in range(n):
    if k < sum_a + a[i]:
        ans = max(ans,i)
        break
    sum_a += a[i]
    sum_b = 0
    for j in range(m):
        if k < sum_a + sum_b + b[j]:
            ans = max(ans,i+1+j)
            break
        sum_b += b[i]
        if j == m-1:
            ans = max(ans,i+1+m)

print(ans)

Submission status: Runtime Error

Solution code:
import sympy


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]


n = int(input())

total = 0
for num in range(1, n+1, 1):
    total += num * len(sympy.divisors(num))
print(total)

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()))
s = 0
ans = 0
while True:  
  if A[0] >= B[0] :
    s += B[0]
    B.pop(0)
    if s < k:
      ans += 1
    else:
      break
  else :
    s += A[0]
    A.pop(0)
    if s < k:
      ans += 1
    else:
      break
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()))

a_i = 0
b_i = 0

result = 0
time = 0

while True:
    if a_i >= len(a) and b_i >= len(b):
        break
    elif a_i >= len(a):
        if time + b[b_i] <= k:
            time += b[b_i]
            result += 1
            b_i += 1
            continue
        else:
            break
    elif b_i >= len(b):
        if time + a[a_i] <= k:
            time += a[a_i]
            result += 1
            a_i += 1
            continue
        else:
            break
    elif a[a_i] >= b[a_i]:
        if time + a[a_i] <= k:
            time += a[a_i]
            result += 1
            a_i += 1
            continue
        else:
            break
    else:
        if time + b[b_i] <= k:
            time += b[b_i]
            result += 1
            b_i += 1
            continue

print(result)

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
cnt = 0
cost = 0
for i, x in enumerate(a):
    cost += x
    if cost > k:
        cnt = i
        cost -= x
        break
else:
    for j, y in enumerate(b):
        cost += y
        if cost > k:
            cnt = n + j
            cost -= y
            break
    else:
        ans = n + m

if cnt <= n:
    i, j = cnt - 1, 0
else:
    i, j = n - 1, cnt - n + 1

while True:
    if cost == 0: break
    if i == n or j == -1: break
    while cost + b[j] <= k:
        j += 1
        cnt += 1
        cost += b[j]
    cost += - a[i] + b[j]
    i, j = i - 1, j + 1
    if cost > k: break
if ans != 0:
    print(ans)
else:
    print(cnt)

Submission status: Runtime Error

Solution code:
#ABC172C
n, m, k = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
i = 0 #Aの掘り具合
j = 0 #Bの掘り具合
ans = 0 #読んだ本の冊数
while k > 0:
    if (A[i] > B[j] or i+1 == len(A)) and B[j] <= k:
        k = k - B[j]
        ans = ans + 1
        j = j + 1
    elif (A[i] < B[j] or j+1 == len(B)) and A[i] <= k:
        k = k - A[i]
        ans = ans + 1
        i = i + 1
    if i + 1 == len(A) and j + 1 == len(B):
        break
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
cnt = 0


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

Submission status: Runtime Error

Solution code:
import sys
# from math import sqrt, gcd, ceil, log
from bisect import bisect
from collections import defaultdict, Counter
inp = sys.stdin.readline
read = lambda: list(map(int, inp().strip().split()))

# sys.setrecursionlimit(10**6)

def func(arr, b):
	return([i-b for i in arr])

def solve():
	a, b, k = read(); a_ = read(); b_ = read()
	for i in range(1, a): a_[i] += a_[i-1]
	for i in range(1, b): b_[i] += b_[i-1]
	ans = 0
	while k > 0:
		inda = bisect(a_, k); indb = bisect(b_, k)
		# print(k, inda, indb, a_[inda-1], b_[indb-1])
		if inda > indb:
			k -= a_[inda-1];
			ans += inda
			a_ = func(a_[inda:], a_[inda-1])
		elif inda == indb:
			if a_[inda-1] < b_[indb-1]:
				k -= a_[inda-1];
				ans += inda
				a_ = func(a_[inda:], a_[inda-1])
			else:
				k -= b_[indb-1];
				ans += indb
				b_ = func(b_[indb:], b_[indb-1])
		else:
			k -= b_[indb-1];
			ans += indb
			b_ = func(b_[indb:], b_[indb-1])


	print(ans)





		

if __name__ == "__main__":
	solve()

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()))
ai = -1
bi = -1
answer = 0
t_sum = 0
if sum(a) + sum(b) <= k:
    print(n + m)
elif sum(a) <= k:
    t_sum = sum(a)
    ai = n-1
    while True:
        bi += 1
        if t_sum + b[bi] > k:
            break
        t_sum += b[bi] 
    bi -= 1
    answer = ai + bi + 2
    while ai >= 0:
        t_sum -= a[ai]
        ai -= 1
        while bi <= m:
            bi += 1
            if t_sum + b[bi] > k:
                break
            t_sum += b[bi]
        bi -= 1
        if ai + bi +2 > answer:
            answer = ai + bi +2
    print(answer)
else:
    while True:
        ai += 1
        if t_sum + a[ai] > k:
            break
        t_sum += a[ai] 
    ai -= 1
    while True:
        bi += 1
        if t_sum + b[bi] > k:
            break
        t_sum += b[bi] 
    bi -= 1
    answer = ai + bi + 2
    while ai >= 0:
        t_sum -= a[ai]
        ai -= 1
        while bi <= m:
            bi += 1
            if t_sum + b[bi] > k:
                break
            t_sum += b[bi]
        bi -= 1
        if ai + bi +2 > answer:
            answer = ai + bi +2
    print(answer)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

a = input().split(" ")
b = input().split(" ")
a = [int(x) for x in a]
b = [int(x) for x in b]

if n<m:
  for i in range(m-n):
    a.append(10000000000)
else:
  for i in range(n-m):
    b.append(10000000000)
    
time = 0
cnt = 0
while True:
  if cnt==n+m: break
  if a[0]<b[0]:
    time += a[0]
    a.pop(0)
  else:
    time += b[0]
    b.pop(0)
  if time<=k: cnt +=1
  else: break
    
print(cnt)

Submission status: Runtime Error

Solution code:
#ABC172C
n, m, k = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
i = 0 #Aの掘り具合
j = 0 #Bの掘り具合
ans = 0 #読んだ本の冊数
while k > 0:
    if (A[i] > B[j] or i+1 == len(A) A[i] > B[j]) and B[j] <= k:
        k = k - B[j]
        ans = ans + 1
        j = j + 1
    elif (A[i] < B[j] or j+1 == len(B) ) and A[i] <= k:
        k = k - A[i]
        ans = ans + 1
        i = i + 1
    if i + 1 == len(A) and j + 1 == len(B):
        break
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()))

#n, m, k = 3, 4, 730
#a = [60, 90, 120]
#b = [80, 150, 80, 150]

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

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

print(ans)

Submission status: Runtime Error

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

a= list(map(int,input().split())) #n冊

b= list(map(int,input().split())) #m冊
#ab=a+b
#print(ab)

if n>m:
    q=0
    while q<(n-m):
        b.append(100000000000)
        q+=1
elif m>n:
    p=0
    while p<(m-n):
        a.append(100000000000)
        p+=1

ab=[110000000000000]*(n+m)
ans=0
count=0
i=0
A=0
B=0
if sum(a)+sum(b)<=k:
    ans=n+m
    print(ans)
else:
    while i<(n+m) and A<=n and B<=m:
        ab[i]=min(a[A],b[B])
        if a[A]>=b[B]:
            B+=1
            i+=1
        else :
            A+=1
            i+=1
    for i in range(n+m):
        ans+=ab[i]
        if ans>k:
            break
        else:
            count+=1
    #print(ab)
    print(count)

Submission status: Runtime Error

Solution code:
import sys
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
abl = sorted(a+b)
ans,cnt = 0,0
if sum(abl) <= k:
	print(len(abl))
	sys.exit()
for i in range(10000):
	ans += abl[i]
	if abl[i] <= k:
		cnt += 1
	else:
		print(cnt)
		sys.exit()

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
count=0
i,j=0,0
while ans<k:
  if i > n-1:
    num=b[j]
  if j > m-1:
    num=a[i]
  else:
    num=min(a[i],b[j])
    if num==a[i]:
      i+=1
      count+=1
      ans+=num
    else:
      j+=1
      count+=1
      ans+=num
  
print(count-1)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
# 標準入力を取得
N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))

# 求解処理
ans = 0
n, m, k = 0, 0, 0
while True:
    if n >= N and m >= M:
        break
    if n >= N:
        k += B[m]
        if k > K:
            break
        ans += 1
        m += 1
        continue
    if m >= M:
        k += A[n]
        if k > K:
            break
        ans += 1
        n += 1
        continue
    A_n, B_m = A[n], B[m]
    if A_n < B_m:
        k += A_n
        n += 1
    elif A_n > B_m:
        k += B_m
        m += 1
    else:
        if n == N:
            k += B_m
            m += 1
        elif m == M:
            k += A_n
            n += 1
        else:
            A_nn, B_mm = A[n+1], B[m+1]
            if A_nn <= B_mm:
                k += A_n
                n += 1
            else:
                k += B_m
                m += 1
    if k > K:
        break
    ans += 1

# 結果出力
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]

def dfs(now_sum,i,j,cnt):
    # print(now_sum)
    # if ans[0] <= cnt:
    #     return
    if now_sum > K:
        # print("a")
        cnt -= 1
        ans[0] = max(ans[0],cnt)
        return
    
    # if i == N or j== M:
        # print("b")
        # print(now_sum,i,j)
    # ans[0] = max(ans[0],cnt)
        # return

    if i < N:
        dfs(now_sum + A[i],i+1,j,cnt+1)
    if j < M:
        dfs(now_sum + B[j],i,j+1,cnt+1)
    ans[0] = max(ans[0],cnt)
    


dfs(0,0,0,0)

print(ans[0])


# 3 3 730
# 60 90 120
# 80 150 80

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_a=[]
t_b=[]
l=0
for i in range(N):
  l+=A[i]
  t_a.append(l)
l=0
for i in range(M):
  l+=B[i]
  t_b.append(l)
def bi_re(i):
  x=t_a[i]
  if x>K:
    return 0
  x=K-x
  l=0;r=M-1
  while l<=r:
    m=(l+r)//2
    q=t_b[m]
    if q==x:
      return m+i+2
    elif q<x:
      l=m+1
    else:
      r=m-1
  for j in range(max(0,m-1),min(M,m+2)):
    if t_b[j]<=x:
      s=j  
  return s+i+2
  
ans=0
for i in range(N):
  ans=max(bi_re(i),ans)
print(ans)