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:
from bisect import *

N,M,K,*f = map(int, open(0).read().split())
A = f[:N]
B = f[N:]
a_read = 0
b_read = 0
csa = [0]
for i in range(N):
    csa.append(csa[i]+A[i])
csb = [0]
for i in range(M):
    csb.append(csb[i]+B[i])
for i in range(N+M):
    if a_read == N:
        bs = bisect_right(csb,K-csa[N])
        b_read = bs - 1
        break
    elif b_read == M:
        bs = bisect_right(csa,K-csb[M])
        b_read = bs - 1
        break
    else:
        if A[a_read] < B[b_read]:
            bs = bisect_right(csa,min(csa[a_read]+B[b_read],K-csb[b_read]))
            if bs <= a_read:
                break
            else:
                a_read = bs - 1
        elif A[a_read] > B[b_read]:
            bs = bisect_right(csb,min(csb[b_read]+A[a_read],K-csa[a_read]))
            if bs <= b_read:
                break
            else:
                b_read = bs - 1
        else:
            if K - csa[a_read] - csb[b_read] >= A[a_read]:
                for j in range(1,N+M):
                    if A[a_read+j] < B[a_read+j]:
                        if K - csa[a_read+j-1] - csb[b_read] >= A[a_read+j]:
                            a_read += j
                            break
                        else:
                            a_read += j - 1
                            break
                    elif A[a_read+j] > B[a_read+j]:
                        if K - csa[a_read] - csb[b_read+j-1] >= B[a_read+j]:
                            b_read += j
                            break
                        else:
                            b_read += j - 1
                            break
                    else:
                        if K - csa[a_read+j-1] - csb[b_read] < A[a_read+j]:
                            a_read += j - 1
                            break
            else:
                break
print(a_read+b_read)

Submission status: Runtime Error

Solution code:
n,m,k = map(int,input().split())
arr0 = list(map(int,input().split()))
arr1 = list(map(int,input().split()))
acc0 = []

for i in range(n):
  acc0.append(acc0[-1] + arr0[i])
acc1 = []
for i in range(m):
  acc1.append(acc1[-1] + arr1[i])
ans = 0
j = m
for i in range(n+1):
  if acc0[i] > k:
    break
  while acc1[j] > k - acc0[i] and j > 0:
    j -= 1
  ans = max(ans, i + j)

print(ans)

Submission status: Runtime Error

Solution code:
N,M,K = input().split()

N = int(N)
M = int(M)
K = int(K)

A = list(input().split())
A = [int(c) for c in A]

B = list(input().split())
B = [int(c) for c in B]

i = 0
j = 0

a = 0
b = 0

while j < K:
    if len(A) == 0 and len(B) == 0:
        break
    elif len(A) == 0:
        if j + B[b] <= K:
            j += B[b]
            i += 1
            b += 1
        else:
            break
    elif len(B) == 0:
        if j + A[a] <= K:
            j += A[a]
            i += 1
            a += 1
        else:
            break
    else:
        if A[a] < B[b]:
            if j + A[a] <= K:
                j += A[a]
                i += 1
                a += 1
            else:
                break
        else:
            if j + B[b] <= K:
                j += B[b]
                i += 1
                b += 1
            else:
                break

print(i)

Submission status: Runtime Error

Solution code:
N,M,K=map(int,input("入力してください").split())
costA=list(map(int,input().split()))
costB=list(map(int,input().split()))
costA=[0]+costA
costB=[0]+costB

for i in range(N):
    costA[i+1]+=costA[i]
    
for i in range(M):
    costB[i+1]+=costB[i]

print(costA)
print(costB)

costB.append(float("inf"))

def upper_bound(list1,K):
    low=0
    high=len(list1)-1 #index
    while high-low!=1:
        mid=(high+low)//2
        if list1[mid]>K:
            high=mid
        else:
            low=mid
    return high  #条件を満たす左側の要素数

number=[]
for i in range(N+1): #A側の机の本を固定 残りの時間でBを二分探索
    time=K-costA[i]
    if upper_bound(costB,time)!=1:
        number.append(i+upper_bound(costB,time)-1)
    else:
        number.append(0)
    print(i)
    print(upper_bound(costB,time))
    print(number)
    
print(max(number))

Submission status: Runtime Error

Solution code:
N,M,K=map(int,input("入力してください").split())
costA=list(map(int,input().split()))
costB=list(map(int,input().split()))
costA=[0]+costA
costB=[0]+costB

for i in range(N):
    costA[i+1]+=costA[i]
    
for i in range(M):
    costB[i+1]+=costB[i]

print(costA)
print(costB)

costB.append(float("inf"))

def upper_bound(list1,K):
    low=0
    high=len(list1)-1 #index
    while high-low!=1:
        mid=(high+low)//2
        if list1[mid]>K:
            high=mid
        else:
            low=mid
    return high  #条件を満たす左側の要素数

number=[]
for i in range(N+1): #A側の机の本を固定 残りの時間でBを二分探索
    time=K-costA[i]
    number.append(i+upper_bound(costB,time)-1)
    print(i)
    print(upper_bound(costB,time))
    print(number)
    
print(max(number))

Submission status: Runtime Error

Solution code:

N, M, lim = map(int, input().split())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))
ans = 0
while lim > 0:
    if As == [] and Bs != []:
        d = Bs.pop(0)
    elif Bs == [] and A != []:
        d = As.pop(0)
    else:
        if As[0] > Bs[0]:
            d = Bs.pop(0)
        elif As[0] < Bs[0]:
            d = As.pop(0)
        else:
            if len(As) == 1 and len(Bs) >1:
                d = Bs.pop(0)
            elif len(As) > 1 and len(Bs) == 1:
                d = As.pop(0)
            elif len(As) == 1 and len(Bs) == 1:
                d = As.pop(0)
            else:
                if As[1] >= Bs[1]:
                    d = Bs.pop(0)
                else:
                    d = As.pop(0)
    lim-= d
    if lim >=0:
        ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
import sys

def syoki(k,skk,atk,):
    sks=ats=0
    for i in range(len(skk)):
        if skk[i]<=k:
            sks=i+1
        else:
            break
    for i in range(len(atk)):
        if atk[i]+skk[sks-1]<=k:
            ats=i+1
        else:
            break
    return(sks,ats)

def keisan(o,s,k,ok,sk,os,ss):
    swk=ss
    for i in range(os-2,-1,-1):
        while k> ok[i]+sk[swk]:
            swk+=1
            if swk<s:
                break
    return max(os+ss,i+swk)

n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ak=[]
aa=0
for i in a:
    aa+=i
    ak.append(aa)
bk=[]
bb=0
for i in b:
    bb+=i
    bk.append(bb)

xa,xb=syoki(k,ak,bk)
yb,ya=syoki(k,bk,ak)
if xa+xb>yb>ya:
    ass=xa
    bs=xb
else:
    ass=ya
    bs=yb

wk=ass+bs

if wk==n+m:
    print(n+m)
    sys.exit()
if ass ==0 and bs==0:
    print(0)
    sys.exit()
if ass>bs:
    an=keisan(n,m,k,ak,bk,ass,bs)
else:
    an=keisan(m,n,k,bk,ak,bs,ass)

print(an)

Submission status: Runtime Error

Solution code:
t1 = []
t2 = []
s1 = input().split(' ')
size1, size2, minutes = int(s1[0]),  int(s1[1]), int(s1[2])
s2 = input().split(' ')
for i in range(len(s2)):
  tmp = int(s2[i])
  if tmp > minutes:
    break
  else:
  	t1.append(tmp)

s3 = input().split(' ')
for i in range(len(s3)):
  tmp = int(s3[i])
  if tmp > minutes:
    break
  else:
  	t2.append(tmp)
   
ans = 0
time1 = 0
time2 = 0
f1 = False
f2 = False
while True:
  consume = 10**9
  if time1 == 0 and t1:
    time1 = t1[0]
  if time2 ==0 and t2:
    time2 = t2[0]
  if consume > time1 and time1 != 0:
    consume = time1
    f1 = True
    f2 = False
  if consume > time2 and time2 != 0:
    consume = time2
    f1 = False
    f2 = True
  elif time1 == time2:
    if t1[1] and t2[1]:
      if t1[1] > t2[1]:
        consume = time2
        f1 = False
        f2 = True
      else:
        consume = time1
        f1 = True
        f2 = False
  if minutes < consume:
    break
  if (f1 == True):
    t1.pop(0)
    minutes -= consume
    time1=0
    f1 =False
  elif (f2 == True):
    t2.pop(0)
    minutes -= consume
    time2 = 0
    f2 = False
  else:
    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()))
a = [0]*(N+1)
b = [0]*(M+1)

#累積和の計算
for i in range(1, N+1):
    a[i] = a[i-1] + A[i-1]
for j in range(1, M+1):
    b[j] = b[j-1] + B[j-1]

ans = 0
for i in range(N+1):
    left = 0
    right = M+1
    while left <= right:
        mid = (left + right)//2
        if b[mid] < K - a[i]:
            left = mid + 1
        elif b[mid] > K - a[i]:
            right = mid - 1
    if b[mid] <= K - a[i]:
        j = mid
    else:
        j = mid - 1
    ans = max(ans, i + j)
print(ans)

Submission status: Runtime Error

Solution code:
t1 = []
t2 = []
s1 = input().split(' ')
size1, size2, minutes = int(s1[0]),  int(s1[1]), int(s1[2])
s2 = input().split(' ')
for i in range(len(s2)):
  t1.append(int(s2[i]))

s3 = input().split(' ')
for i in range(len(s3)):
  t2.append(int(s3[i]))

ans = 0
while True:
  time1 = 0
  time2 = 0
  if t1:
    time1 = t1[0]
  if t2:
    time2 = t2[0]
  if time1 == 0 and time2 == 0:
    break
  if minutes < min(time1,time2):
    break
  if time1 < time2 or time2 == 0:
    t1.pop(0)
    minutes -=time1
  elif time2< time1 or time1 == 0:
    t2.pop(0)
    minutes -=time2
  ans +=1
  
print(ans)

Submission status: Runtime Error

Solution code:
class queue:
  data = []
  def __init__(self):
    self.data = []
  def push(self,data):
    self.data.append(data)
  def pop(self):
    return self.data.pop(0)
  def peek(self):
    return self.data[0]

t1 = queue()
t2 = queue()
s1 = input().split(' ')
size1, size2, minutes = int(s1[0]),  int(s1[1]), int(s1[2])
s2 = input().split(' ')
for i in range(len(s2)):
  t1.push(int(s2[i]))

s3 = input().split(' ')
for i in range(len(s3)):
  t2.push(int(s3[i]))

ans = 0
while True:
  time1 = 0
  time2 = 0
  if t1.data:
    time1 = t1.peek()
  if t2.data:
    time2 = t2.peek()
  if time1 == 0 and time2 == 0:
    break
  if minutes < min(time1,time2):
    break
  if time1 < time2:
    t1.pop()
    minutes -=time1
  elif time2< time1:
    t2.pop()
    minutes -=time2
  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()))

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 j 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 = 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 j in range(n+1):
    if A[i] > k:
        break
    while B[j] > k - B[i]:
        j -= 1
    ans = max(ans,i+j)
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 = [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 j 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=map(int,input().split())
A=list(map(int, input().split()))
B=list(map(int, input().split()))

#入力終わり


#累積和とる

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

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

#累積和計算おわり


ans = 0
end = N #二分探索の後に設定しなおしたいので先に設定しておく

for i in range(M+1):#Bを順番に増やしていくよー
    A_use = K-B_wa[i]
    if A_use<0: #Bだけでこえてる
        break
    
    ##Aは最大で何冊よめるかな
    A_MAX = 0
    start = 0
    while  end-start>=1 : #調べるのが2個以上
        now = int((start + end+1)/2) #切り上げ
        if A_wa[now]==A_use :  #A[i]がKと一致
            A_MAX = now #ここが最大
            break
        elif A_wa[now]<A_use : #A[i]がKより小さい
            start = now #目的の値はここ以上のとこにある
            A_MAX = now #現時点での最大値
        else : #A[i]がKより大きい
            end = now-1#目的の値はここより小さい
    ##Aの最大探すの終わり
    
    #これ最大？
    if A_MAX+i>ans :
        ans=A_MAX+i

    end=A_MAX　#endの再設定

#コンソールにだす
print(ans)

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

tempa=0
for i in range(len(a)):
    a[i]+=tempa
    tempa=a[i]

tempb=0
for i in range(len(b)):
    b[i]+=tempb
    tempb=b[i]

ans=0
j=len(b)-1

for i in range(len(a)):
    #print(i,j, a[i], b[j])
    if a[i]>k:
        break
    while b[j]>k-a[i]:
        #print(b[j], k-a[i])
        j-=1
    #print(i,j)
    ans=max(ans, i+j+2)
    
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()))
b = sum(B)
ka = k
i = m
re = 0
for a in A:
  if ka < 0:
    break
  while ka < b and i > 0:
    b -= B[i]
    i -= 1
  ka -= a
  re += 1
  
print(re+i)

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]
for i in range(n):
  a_sum.append(a[i] + a_sum[i])
b_sum = [0]
for i in range(m):
  b_sum.append(b[i] + b_sum[i])

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

Submission status: Runtime Error

Solution code:
import java.io.*;
import java.util.*;
class Main{
	public static void main(String[] args) throws IOException{
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String[] lo = reader.readLine().split(" ");
		int n = Integer.parseInt(lo[0]);
		int m = Integer.parseInt(lo[1]);
		int k = Integer.parseInt(lo[2]);
		int[] As = Arrays.stream(reader.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
		int[] Bs = Arrays.stream(reader.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
		long[] psumA = new long[n+1];
		long[] psumB = new long[m+1];
		psumA[0] = 0;
		psumB[0] = 0;
		for(int i = 1;i<n+1;i++) psumA[i] = psumA[i-1]+As[i-1];
		for(int i = 1;i<m+1;i++) psumB[i] = psumB[i-1]+Bs[i-1];
		int j = m-1;
		int res = 0;
		for(int i = 0;i<n;i++){
			if(psumA[i]>k) break;
			while(j>=0 && psumB[j]>k-psumA[i]){
				j--;
			}
			if(j>=0 && psumB[j] <= k-psumA[i]) res = Math.max(res,i+j);
			//if(j<0 && (k-psumA[i])>=0) res= Math.max(res,i+1);
		}
		System.out.println(res);
	}
}

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()))
def calc(i,j,l):
    if i==n and j!=m and l>=0:
        ans=calc(i,j+1,l-b[j])
    elif i!=n and j==m and l>=0:
        ans=calc(i+1,j,l-a[i])
    elif l<0:
        ans=i+j-1
    elif i==n and j==m and l>=0:
        ans=i+j
    else:
        ans=max(calc(i,j+1,l-b[j]),calc(i+1,j,l-a[i]))
    return ans
print(calc(0,0,k))

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()))
def calc(i,j,k):
    if i==n and j!=m and k>=0:
        ans=calc(i,j+1,k-b[j])
    elif i!=n and j==m and k>=0:
        ans=calc(i+1,j,k-a[i])
    elif k<0:
        ans=i+j-1
    elif i==n and j==m and k>=0:
        ans=i+j
    else:
        ans=max(calc(i,j+1,k-b[j]),calc(i+1,j,k-a[i]))
    return ans
print(calc(0,0,k))

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()))
def calc(i,j,k):
    if i==n-1 and j!=m-1 and k>0:
        ans=calc(i,j+1,k-b[j])
    elif i!=n-1 and j==m-1 and k>0:
        ans=calc(i+1,j,k-a[i])
    elif k<=0:
        ans=i+j-1
    elif i==n-1 and j==m-1 and k>0:
        ans=i+j+2
    else:
        ans=max(calc(i,j+1,k-b[j]),calc(i+1,j,k-a[i]))
    return ans
print(calc(0,0,k))

Submission status: Runtime Error

Solution code:
import bisect
import sys

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

a_accumulated = [0] * n
b_accumulated = [0] * m

for idx, a in enumerate(A):
    a_accumulated[idx] += a_accumulated[idx - 1] + a # idx == 0の場合はa_accumulated[-1]を参照するが、それは0初期化されているので問題ない。

for idx, b in enumerate(B):
    b_accumulated[idx] += b_accumulated[idx - 1] + b

a_limit = bisect.bisect_right(a_accumulated, k)
if a_limit == 0:
    position = bisect.bisect_right(b_accumulated, k - a_accumulated[i])
    print(position)
    sys.exit(0)

best_num = 0
for i in reversed(range(0, a_limit)):
    position = bisect.bisect_right(b_accumulated, k - a_accumulated[i])
    best_num = max(best_num, i + position + 1)
print(best_num)

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()))
    C = []
    for x in range(1,n+1):
        sumA = sum(A[0:x])
        for y in range(1,m+1):
            sumB = sum(B[0:y])
            if sumA + sumB < k:
                C.append(sumA + sumB)
    print(max(C))
main()

Submission status: Runtime Error

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

a=0;b=0
cnt=0
while a < len(A) and b < len(B) and K > 0:
  a_ = A[a]
  b_ = B[b]
    
  if a_ > K and b_ > K:
    break
      
  if a_ < b_ and a_ <= K:
    cnt += 1
	K -= a_
    a += 1
  elif a_ >= b_ and b_ <= K:
    cnt += 1
    K -= b_
    b += 1
      
print(cnt)

Submission status: Runtime Error

Solution code:
a=0;b=0
cnt=0
while a < len(A) and b < len(B) and K > 0:
	a_ = A[a]
	b_ = B[b]
    
    if a_ > K and b_ > K:
      break
      
    if a_ < b_ and a_ <= K:
		cnt += 1
		K -= a_
        a += 1
	elif a_ >= b_ and b_ <= K:
      cnt += 1
      K -= b_
      b += 1
      
print(cnt)

Submission status: Runtime Error

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

a=0;b=0
cnt=0
while a < len(A) and b < len(B) and K > 0:
	a_ = A[a]
	b_ = B[b]
    
    if a_ > K and b_ > K:
      break
      
    if a_ < b_ and a_ <= K:
		cnt += 1
		K -= a_
		A.pop(0)
	elif a_ >= b_ and b_ <= K:
      cnt += 1
      K -= b_
      B.pop(0)
      
print(cnt)

Submission status: Runtime Error

Solution code:
import numpy as np
 
n,m,k=map(int,input().split())
A=[0]+list(map(int,input().split()))
B=[0]+list(map(int,input().split()))
sumA = np.cumsum(A)
sumB = np.cumsum(B)
#print(sumA)
#print(sumB)
ab=np.array([sumA]*(m+1))+np.array([sumB]*(n+1)).T

Submission status: Runtime Error

Solution code:
import numpy as np

n,m,k=map(int,input().split())
A=[0]+list(map(int,input().split()))
B=[0]+list(map(int,input().split()))
sumA = np.cumsum(A)
sumB = np.cumsum(B)
#print(sumA)
#print(sumB)
ab=np.array([sumA]*(m+1))+np.array([sumB]*(n+1)).T
tf=ab<=k

Submission status: Runtime Error

Solution code:
import numpy as np

n,m,k=map(int,input().split())
A=[0]+list(map(int,input().split()))
B=[0]+list(map(int,input().split()))
sumA = np.cumsum(A)
sumB = np.cumsum(B)
#print(sumA)
#print(sumB)
ab=np.array([sumA]*(m+1))+np.array([sumB]*(n+1)).T
tf=ab<=k
print(ab)
ans=0
i=0

for tf_ in tf:
    s=sum(tf_)
    x=i+s-1
    if s>0 and x>ans:
        ans=x
    i+=1
    
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

n,m,k=map(int,input().split())
A=[0]+list(map(int,input().split()))
B=[0]+list(map(int,input().split()))
sumA = np.cumsum(A)
sumB = np.cumsum(B)
#print(sumA)
#print(sumB)
ab=np.array([sumA]*(m+1))+np.array([sumB]*(n+1)).T
tf=ab<=k
#print(tf)
ans=0
i=0

for tf_ in tf:
    s=sum(tf_)
    x=i+s-1
    if s>1 and x>ans:
        ans=x
    i+=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()))

for i in range(n):
    if i == 0:
        continue
    else:
        a[i] += a[i-1]

for i in range(m):
    if i == 0:
        continue
    else:
        b[i] += b[i - 1]

a = [0]+a
b = [0]+b

i = 0
j = m
ans = 0

while a[i] <= k:
    while b[j] > k-a[i]:
        j -= 1
    ans = i+j
    ans =max(ans,i+j)
    i += 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()))

k=0
a=0
b=0
count=0

while k<K:
  if a<N:
    if A[a]<=B[b]:
      k+=A[a]
      count+=1
      a+=1
    elif A[a]>B[b]:
      k+=B[b]
      count+=1
      b+=1
  elif a==N and B<M:
    k+B[b]
    count+=1
    b+=1
  else:break
    
if k>K:print(count-1)
else:print(count)

Submission status: Runtime Error

Solution code:
#入力:N,M(int:整数)
def input2():
	return map(int,input().split())
  
n,m,k=input2()
A=input_array()
B=input_array()

ca=0
cb=0
count=0
SUM=0
for i in range(n+m):
	if ca >= n:
		SUM+=B[cb]
		cb+=1
	elif cb >= m:
		SUM+=A[ca]
		ca+=1
	elif A[ca]<=B[cb]:
		SUM+=A[ca]
		ca+=1
	else:
		SUM+=B[cb]
		cb+=1

	if SUM >k:
		break
	else:
		count+=1
print(count)

Submission status: Runtime Error

Solution code:
n,m,k=input2()
A=input_array()
B=input_array()

ca=0
cb=0
count=0
SUM=0
for i in range(10**5):
	if A[ca]<=B[cb]:
		SUM+=A[ca]
		ca+=1
	else:
		SUM+=B[cb]
		cb+=1

	if SUM >=k:
		break
	else:
		count+=1
print(count)

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

from collections import deque
sa = deque([x for x in a])
sb = deque([x for x in b])
sa.append(10**9+1)
sb.append(10**9+1)
ans = 0
def cnt(a,b,time):
  global ans
  #print(ans, time,a,b)
  if (time <= k) & ( (len(a) > 1) | (len(b) > 1)):
    if a[0] < b[0]:
      time += a[0]
      a.popleft()
    else:
      time += b[0]
      b.popleft()
    if time <= k:
      ans += 1
      if (time <= k) & ( (len(a) > 1) | (len(b) > 1)):
        #cnt(a,b,time)

cnt(sa,sb,0)
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()))

from collections import deque
sa = deque([x for x in a])
sb = deque([x for x in b])
sa.append(10**9+1)
sb.append(10**9+1)
ans = 0
def cnt(a,b,time):
  global ans
  #print(ans, time,a,b)
  if (time <= k) & ( (len(a) > 1) | (len(b) > 1)):
    if a[0] < b[0]:
      time += a[0]
      a.popleft()
    else:
      time += b[0]
      b.popleft()
    if time <= k:
      ans += 1
      if (time <= k) & ( (len(a) > 1) | (len(b) > 1)):
        cnt(a,b,time)

cnt(sa,sb,0)
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()))

from collections import deque
sa = deque([x for x in a])
sb = deque([x for x in b])
sa.append(10**9+1)
sb.append(10**9+1)
ans = 0
def cnt(a,b,time):
  global ans
  #print(ans, time,a,b)
  if (time <= k) & ( (len(a) > 1) | (len(b) > 1)):
    if a[0] < b[0]:
      time += a[0]
      a.popleft()
    else:
      time += b[0]
      b.popleft()
    if time <= k:
      ans += 1
      cnt(a,b,time)

cnt(sa,sb,0)
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()))

from collections import deque
sa = deque([x for x in a])
sb = deque([x for x in b])
sa.append(10**9+1)
sb.append(10**9+1)
ans = 0
def cnt(a,b,time):
  global ans
  #print(ans, time,a,b)
  if (time <= k) & ( (len(a) > 1) | (len(b) > 1)):
    if a[0] < b[0]:
      #time += a[0]
      a.popleft()
    else:
      #time += b[0]
      b.popleft()
    if time <= k:
      ans += 1
      cnt(a,b,time)

cnt(sa,sb,0)
print(ans)

Submission status: Runtime Error

Solution code:
from collections import deque
n,m,k = map(int,input().split())
la = list(map(int,input().split()))
lb = list(map(int,input().split()))
ls = la + lb[::-1]
ls = deque(ls)
inf = float("inf")
dp = [[-inf]*(k+1) for _ in range(n+m+1)]
for j in range(k+1):
    dp[0][j] = 0
for i in range(n+m):
    if ls == deque([]):
        break
    elif ls[0] <= ls[-1]:
        s = ls.popleft()
    else:
        s = ls.pop()
    for l in range(k+1):
        if l-s >=0:
            dp[i+1][l] = max(dp[i][l],dp[i][l-s]+1)
        else:
            dp[i+1][l] = dp[i][l]
print(dp[-1][k])

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 = sorted(A.append(B))
j = 0
k = 0

for i in range(N + M):
  j += C[i]
  k += 1
  if j > K:
    break

print(k-1)

Submission status: Runtime Error

Solution code:
import numpy as np
import sys
read = sys.stdin.buffer.read


N, M, K = map(int, input().split())
AB = np.array(read().split(), np.int32)
A = [0] + np.cumsum(AB[:N]).tolist()
B = [0] + np.cumsum(AB[N:]).tolist()
assert (N == len(A) - 1) and (M == len(B) - 1)

left = 0
for i, b in enumerate(B):
    if b > K:
        left = i - 1
        break

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

        while A[i] + B[left] > K:
            left -= 1

        ans = max(ans, left + i)

print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
import sys
read = sys.stdin.buffer.read


N, M, K = map(int, input().split())
AB = np.array(read().split(), np.int32)
A = [0] + np.cumsum(AB[:N]).tolist()
B = [0] + np.cumsum(AB[N:]).tolist()
assert (N == len(A) - 1) and (M == len(B) - 1)

left = M
for i, b in enumerate(B):
    if b > K:
        left = i

ans = 0
for i in range(len(A)):
    if A[i] > K:
        break

    while A[i] + B[left] > K:
        left -= 1

    ans = max(ans, left + i)

print(ans)

Submission status: Runtime Error

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

#０冊を初期値にする
A=[0]
B=[0]


for a in At:
    if A[-1]+a<K:
        A.append(A[-1]+a)

for b in Bt:
    if B[-1]+b<K:
        B.append(B[-1]+b)
print (A,B)

def is_ok(arg):
    # 条件を満たすかどうか？問題ごとに定義
    if Ak+B[arg]<=K:
        return True
    else:
        return False


def meguru_bisect(ng, ok):
    '''
    めぐる2分探査
    okはBの冊数たりうる値
    ngはBの冊数たり得ない値を入れる。
    '''

    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return ok


Ak=0

maxBooks=0
for Ai in range(len(A)): 
    Ak=A[Ai]
    Bi=meguru_bisect(len(B),0) #len(B)は配列の要素数として使われるとき最大＋１
    if maxBooks<(Ai+Bi):
        maxBooks=Ai+Bi
print( maxBooks )

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])
a.pop(0)
b.pop(0)
j=m-1
x=0
for i in range(n-1,-1,-1):
  if a[i]>k:
    continue
  while b[j]>k-a[i]:
    j-=1
  x=max(x,i+j+2)
print(x)

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:
from sys import stdin, stdout
input = stdin.readline
print = stdout.write
n, m, k = map(int, input().split())
a, b = [0], [0]
a += list(map(int, input().split())),
b += list(map(int, input().split())),
for i in range(1, n + 1):
    a[i] += a[i - 1]
for i in range(1, m + 1):
    b[i] += b[i - 1]
i, j, z = 0, m, 0
while i <= n and a[i] <= k:
    while b[j] > k - a[i]:
        j -= 1
    z = max(z, i + j)
    i += 1
print(str(z))

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_pre,b_pre=[0],[0]

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

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

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

	ans=max(ans,i+j)

print(ans)

Submission status: Runtime Error

Solution code:
from sys import stdin
n,m,k = map(int, stdin.readline().rstrip().split())
a = list(map(int, stdin.readline().rstrip().split()))
b = list(map(int, stdin.readline().rstrip().split()))

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

def ans(A, B):
    for i in range(0, n + 1):
        j = 0
        while A[i] + B[j + 1] <= k:
            j += 1
            if j == len(B) - 1:
                break

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

if A[1] > k and B[1] > k:
    print(0)
else:
    res = ans(A, B)
    print(res)

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

import numpy as np
import bisect
a = np.cumsum(a)
b = np.cumsum(b)
ans = 0
r = m
for i in range(n+1):
  if a[i] > k:
    break
  while a[i] + b[r] > k:
    r -= 1
  ans = max(ans, i+r)

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

import numpy as np
import bisect
a = np.cumsum(a)
b = np.cumsum(b)
ans = 0
r = m
for i in range(n+1):
  if a[i] > k:
    break
  while a[i] + b[r] > k:
    r -= 1
  ans = max(ans, i+r)
if i == 0:
  r = bisect.bisect_left(b, k)
  ans = max(ans, i+r)
print(ans)