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:
for i in range(1, N + 1):
    A_ls[i] += A_ls[i - 1]
for i in range(1, M + 1):
    B_ls[i] += B_ls[i - 1]

b_cnt, rst = M, 0
for a_cnt in range(N + 1):
    if A_ls[a_cnt] > K:
        break
    while A_ls[a_cnt] + B_ls[b_cnt] > K:
        b_cnt -= 1
    rst = max(rst, a_cnt + b_cnt)
print(rst)

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 j 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 = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

max_count = 0
for i in range(n):
	a_sum = sum(a[:i + 1])
	for j in range(m):
		b_sum = sum(b[:j + 1])
		if (a_sum + b_sum <= k) && (a_sum + b_sum > max_count):
			max_count = i + j + 2
print(max_count)

Submission status: Runtime Error

Solution code:
N,M,K=map(int,input().split())
N-=1
M-=1
a=list(map(int,input().split()))
b=list(map(int,input().split()))
SUM_TIME=0
SUM_NUMBER=0
if (a[N]<=K)or(b[M]<=K):
    
    while SUM_TIME<=K:
        if (a[N]<b[M]):
            SUM_TIME+=a[N]
            N-=1
        else:
            SUM_TIME+=b[M]
            M-=1
        SUM_NUMBER+=1
print(SUM_NUMBER)

Submission status: Runtime Error

Solution code:

a=list(map(int,input().split()))
b=list(map(int,input().split()))
SUM_TIME=0
SUM_NUMBER=0
if (a[N]<=K)or(b[M]<=K):
    
    while SUM_TIME<=K:
        if (a[N]<b[M]):
            SUM_TIME+=a[N]
            N-=1
        else:
            SUM_TIME+=b[M]
            M-=1
        SUM_NUMBER+=1
print(SUM_NUMBER)

Submission status: Runtime Error

Solution code:
import bisect
import numpy as np

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

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

def check(x, y):
    return cumA[x] + cumB[y] <= K

# A から x 冊, B から y 冊とする
x0 = bisect.bisect_left(cumA, K)
ans = 0

for x in range(x0, -1, -1):
    capacity = K - cumA[x]
    y = bisect.bisect_left(cumB, capacity)
    if check(x, y):
        ans = max(ans, x+y)

print(ans)

Submission status: Runtime Error

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

    books = 0
    while 0 < k:
        print(f'{a=}')
        print(f'{b=}')
        print(f'{k=}')
        print(f'{books=}')
        if k < 0:
            print(books-1)
            exit()
        if not a:
            k -= b[0]
            b.pop(0)
            books += 1
            continue
        elif not b:
            k -= a[0]
            a.pop(0)
            books += 1
            continue

        if a[0] < b[0]:
            k -= a[0]
            a.pop(0)
            books += 1
        elif b[0] < a[0]:
            k -= b[0]
            b.pop(0)
            books += 1
        elif k < a[0] and k < b[0]:
            break
        else:
            for i, j in zip(a, b):
                if i < j:
                    k -= a[0]
                    a.pop(0)
                    books += 1
                elif j < i:
                    k -= b[0]
                    b.pop(0)
                    books += 1

    print(books)


def Qd():
    pass


if __name__ == '__main__':
    Qc()

Submission status: Runtime Error

Solution code:
n, m, k = map(int,input().split())
li = list(map(int,input().split()))[:n]
li2 = list(map(int,input().split()))[:m]
all = 0
g = 0
i = 0
c = 0
while all < k:
    if n == i:
        all += li2[c]
        c += 1
    elif k == c:
        all += li[i]
        i += 1
    else:
        if li[i] > li2[c]:
            all += li2[c]
            c += 1
        else:
            all += li[i]
            i += 1
    if all <= k:
        g += 1

print(g)

Submission status: Runtime Error

Solution code:
n, m, k = map(int,input().split())
li = list(map(int,input().split()))[:n]
li2 = list(map(int,input().split()))[:m]
all = 0
g = 0
while all <= k:
    if len(li) != 0 and len(li2) != 0:
        if li[0] >= li2[0]:
            all += li2.pop(0)
        else:
            all += li.pop(0)
        if all <= k:
            g += 1
    else:
        if len(li) == 0:
            all += li2.pop(0)
        else:
            all += li2.pop(0)
        if all <= k:
            g += 1
print(g)

Submission status: Runtime Error

Solution code:
n, m, k = map(int,input().split())
li = list(map(int,input().split()))[:n]
li2 = list(map(int,input().split()))[:k]
all = 0
g = 0
while all < k:
    if len(li) != 0 and len(li2) != 0:
        if li[0] >= li2[0]:
            all += li2.pop(0)
        else:
            all += li.pop(0)
        if all <= k:
            g += 1
    else:
        if len(li) == 0:
            all += li2.pop(0)
        else:
            all += li2.pop(0)
        if all <= k:
            g += 1
print(g)

Submission status: Runtime Error

Solution code:
n, m, k = map(int,input().split())
li = list(map(int,input().split()))[:n]
li2 = list(map(int,input().split()))[:k]
all = 0
g = 0
while all < k:
    if len(li) != 0 and len(li2) != 0:
        if li[0] >= li2[0]:
            all += li2.pop(0)
        else:
            all += li.pop(0)
        if all <= k:
            g += 1
    else:
        break
while all < k:
    if len(li) == 0:
        all += li2.pop(0)
    else:
        all += li2.pop(0)
    if all <= k:
        g += 1
print(g)

Submission status: Runtime Error

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

AS = []
BS = []

suma = 0
for a in A:
  suma += a
  AS.append(suma)
  
sumb = 0
for b in B:
  sumb += b
  BS.append(sumb)
  
maxC = 0
for aIndex, a in enumerate(AS):
  bIndex = getIndex(BS, K - a)
  score = aIndex + 1 + bIndex
  if score > maxC:
    score = maxC

def getIndex(List, S):
  import copy
  l = copy.deepcopy(list)
  start = 0
  end = len(l)
  
  while True
    if end - start == 1:
      break
    mid = (end - start) // 2
    if l[mid] >= S:
      end = mid
    else:
      start = mid
  return start

print(maxC)

Submission status: Runtime Error

Solution code:
import numpy as np
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ans = 0
A_array = np.array(A)
B_array = np.array(B)
A_cum = np.cumsum(A_array)
B_cum = np.cumsum(B_array)
for i in range(len(A_cum)):
    k = A_cum[i]
    if k >K:
        break
    a = 0
    b = len(B_cum)-1
    print(B_check)
    while b - a != 0:
        c = int(round((a+b)/2))
        if B_check[c] < 0:
            b = c
        else:
            a = c
        if b-a == 1:
            if B_check[b] < 0:
                b = a
            else:
                a = b
    check = i+b+2
    if check>ans:
        ans = check
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ans = 0
A_array = np.array(A)
B_array = np.array(B)
A_cum = np.cumsum(A_array)
B_cum = np.cumsum(B_array)
for i in range(len(A_cum)):
    k = A_cum[i]
    if k >K:
        break
    a = 0
    b = len(B_cum)-1
    print(B_check)
    while b - a != 0:
        c = round((a+b)/2)
        if B_check[c] < 0:
            b = c
        else:
            a = c
        if b-a == 1:
            if B_check[b] < 0:
                b = a
            else:
                a = b
    check = i+b+2
    if check>ans:
        ans = check
print(ans)

Submission status: Runtime Error

Solution code:
#k分たったときには机Aの本を上から何冊か、机Bの本を上から何冊か読んでることになる
#つまり机A,Bの方で読んだ本の合計時間は累積和で計算可能
#あとはその範囲内で全探索すればいい
#その際Aの読む数を決めておけばBの方は2分探索で決められる
n,m,k=list(map(int,input().split()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
from itertools import accumulate
a=[0]+list(accumulate(a))
b=[0]+list(accumulate(b))
from bisect import bisect_right
c=bisect_right(a,k)
ans=0
for i in range(c-1):
  ans=max(ans,i+bisect_right(b,k-b[i]))

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

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

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

        while a[i] + b[j] > K:
            j -= 1

        ans = max(ans, i + j)

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

X = 0
I = 0
J = 0



def read(i,j,k,x):
  
#  print('i',i,' j',j,' k',k,' x',x)
  
  if i == len(A):
    ans1 = x
  else:
    if k >= A[i]:
      ans1 = read(i+1,j,k-A[i],x+1)
    else:
      ans1 = x
  
  if j == len(B):
    ans2 = x
  else:
    if k >= B[j]:
      ans2 = read(i,j+1,k-B[j],x+1)
    else:
      ans2 = x
  
  return max(ans1,ans2)
  
print(read(I,J,K,0))

Submission status: Runtime Error

Solution code:
N,M,K=input(),input(),input()
int(input(A)) =[]
int(input(B)) =[]
 
sum=0
c=0
while sum < K:
  if A[i]<B[j]:
    sum = sum + B[j]
    c=c+1
  else:
    sum = sum + A[i]
    c=c+1
print(c)

Submission status: Runtime Error

Solution code:
N,M,K=input(),input(),input()
int(input(A)) =[]
int(input(B)) =[]
 
sum=0
c=0
while sum < K:
  if A[i]<B[j]:
    sum = sum + B[j]
    c=c+1
  else:
    sum = sum + A[i]
    c=c+1
print(sum)

Submission status: Runtime Error

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

c=suma=sumb=0
for a in A:
    if k>=suma+a :
        suma += a
        c+=1

ia=c-1
maxc=c
i=0
while( i < len(B) ):
  
    if k>=suma+sumb+B[i] :
        sumb += B[i]
        i+=1
        c+=1
        maxc=c
    elif k>=suma+sumb+B[i]-A[ia]:
        sumb += B[i]
        i+=1
        suma -=A[ia]
        ia-=1
    else:
        suma -=A[ia]
        ia-=1
        c-=1

print( maxc )

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=suma=sumb=0
for a in A:
    if k>=suma+a :
        suma += a
        c+=1

ia=c
maxc=c
for b in B:
  
    if k>=suma+sumb+b :
        sumb += b
        c+=1
        maxc=c
    elif k>=suma+sumb+b-A[ia]:
        sumb +=b
        suma -=A[ia]
        ia-=1
    else:
        suma -=A[ia]
        ia-=1
        c-=1

print( maxc )

Submission status: Runtime Error

Solution code:
import numpy as np
N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A.insert(0,0)
B.insert(0,0)
for i in range(1,N+1):
  A[i] += A[i-1]
  if A[i] > K: break
for i in range(1,M+1):
  B[i] += B[i-1]
  if B[i] > K: break
MAX_K = 10 ** 9
MAX_DEPTH = N+M
data = [0] * MAX_DEPTH

for i in range(1, N+M+1):
  value = MAX_K
  for aNum in range(i+1):
    bNum = i - aNum
    if aNum <= N and bNum <= M:
      tempValue = A[aNum] + B[bNum]
      if tempValue < value:
        value = tempValue
  if value > K:
    print(i-1)
    exit()
print(N+M)

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()))
A.insert(0,0)
B.insert(0,0)
MAX_K = 10 ** 9
MAX_DEPTH = N+M
data = [0] * MAX_DEPTH

for i in range(1, N+M+1):
  value = MAX_K
  A[i] += A[i-1]
  B[i] += B[i-1]
  for aNum in range(i+1):
    bNum = i - aNum
    if aNum <= N and bNum <= M:
      tempValue = A[aNum] + B[bNum]
      if tempValue < value:
        value = tempValue
  if value > K:
    print(i-1)
    exit()
print(N+M)

Submission status: Runtime Error

Solution code:
import numpy as np

a = list(map(int,input().split()))

n = [0]
m = [0]

n.extend(list(map(int,input().split())))
m.extend(list(map(int,input().split())))

i = 0
j = 0
ans = 0
bsum = 0
maxsum = 0

nsum = np.cumsum(n)
msum = np.cumsum(m)
for k in range(1,200001):
    if k > a[0]:
        break
    bsum = a[2] - nsum[k]
    while msum[j] <= bsum:
        j += 1
        if j > a[1]:
            break
    j -= 1
    i = k
    if maxsum < i + j:
        maxsum = i + j
print(str(maxsum))

Submission status: Runtime Error

Solution code:
import numpy as np

a = list(map(int,input().split()))

n = [0]
m = [0]

n.extend(list(map(int,input().split())))
m.extend(list(map(int,input().split())))

i = 0
j = 0
ans = 0
bsum = 0
maxsum = 0

nsum = np.cumsum(n)
msum = np.cumsum(m)
for k in range(1,200001):
    if k > a[0]:
        break
    bsum = a[2] - nsum[k]
    while msum[j] < bsum:
        j += 1
        if j > a[1]:
            break
    j -= 1
    i = k
    if maxsum < i + j:
        maxsum = i + j
print(str(maxsum))

Submission status: Runtime Error

Solution code:
import numpy as np

a = list(map(int,input().split()))

n = [0]
m = [0]

n.extend(list(map(int,input().split())))
m.extend(list(map(int,input().split())))

i = 0
j = 0
ans = 0
bsum = 0
maxsum = 0

nsum = np.cumsum(n)
msum = np.cumsum(m)
for k in range(1,200001):
    if k > a[0]:
        break
    bsum = a[2] - nsum[k]
    while msum[j] < bsum:
        j += 1
    j -= 1
    i = k
    if maxsum < i + j:
        maxsum = i + j
print(str(maxsum))

Submission status: Runtime Error

Solution code:
a = list(map(int,input().split()))

n = [0]
m = [0]

n.extend(list(map(int,input().split())))
m.extend(list(map(int,input().split())))

i = 0
j = 0
ans = 0
bsum = 0
maxsum = 0

nsum = np.cumsum(n)
msum = np.cumsum(m)
for k in range(1,200001):
    if k > a[0]:
        break
    bsum = a[2] - nsum[k]
    if bsum < 0:
        break
    idx = np.abs(np.asarray(msum) - bsum).argmin()
    if msum[idx] > bsum:
        j = idx - 1
    else:
        j = idx
    i = k
    if maxsum < i + j:
        maxsum = i + j
print(str(maxsum))

Submission status: Runtime Error

Solution code:
import numpy

a = list(map(int,input().split()))

n = [0]
m = [0]

n.extend(list(map(int,input().split())))
m.extend(list(map(int,input().split())))

i = 0
j = 0
ans = 0
bsum = 0

nsum = numpy.cumsum(n)
msum = numpy.cumsum(m)
print(nsum)
for k in range(400000):
    if i > a[0]:
        while(nsum[i] + msum[j] <= a[2]):
            j += 1
            if j > a[1] and nsum[i] + msum[j] <= a[2]:
                j += 1
                break
        ans = i + j - 1
        break
    elif j > a[1]:
        while(nsum[i] + msum[j] <= a[2]):
            i += 1
            if i > a[0] and nsum[i] + msum[j] <= a[2]:
                i += 1
                break
        ans = i + j - 1
        break
    if nsum[i] > msum[j]:
        j += 1
    else:
        i += 1
    if nsum[i] + msum[j] > a[2]:
        ans = i + j - 1
        break
print(str(ans))

Submission status: Runtime Error

Solution code:
a = list(map(int,input().split()))

n = [0]
m = [0]

n.extend(list(map(int,input().split())))
m.extend(list(map(int,input().split())))

i = 0
j = 0
ans = 0
bsum = 0

nsum = numpy.cumsum(n)
msum = numpy.cumsum(m)
print(nsum)
for k in range(400000):
    if i > a[0]:
        while(nsum[i] + msum[j] <= a[2]):
            j += 1
            if j > a[1] and nsum[i] + msum[j] <= a[2]:
                j += 1
                break
        ans = i + j - 1
        break
    elif j > a[1]:
        while(nsum[i] + msum[j] <= a[2]):
            i += 1
            if i > a[0] and nsum[i] + msum[j] <= a[2]:
                i += 1
                break
        ans = i + j - 1
        break
    if nsum[i] > msum[j]:
        j += 1
    else:
        i += 1
    if nsum[i] + msum[j] > a[2]:
        ans = i + j - 1
        break
print(str(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()))

# print(a)
# print(b)
i = 0
j = 0
flag = 0

while i < len(a) and j < len(b):
    if k < 0:
        print(flag)
        exit()
    elif a[i] <= b[j]:
        k -= a[i]
        i += 1
        if k >= 0:
            flag += 1
    else:
        k -= b[j]
        j += 1
        if k >= 0:
            flag += 1

if i >= len(a):
    while j < len(b):
        if k < 0:
            print(flag)
            exit()
        else:
            k -= b[j]
            j += 1
            if k >= 0:
                flag += 1
else:
    while i < len(a):
        if k < 0:
            print(flag)
            exit()
        else:
            k -= b[i]
            i += 1
            if k >= 0:
                flag += 1
print(flag)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**7)
import bisect
import heapq
import itertools
import math
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from math import gcd
from operator import add, itemgetter, mul, xor
def cmb(n,r,mod):
  bunshi=1
  bunbo=1
  for i in range(r):
    bunbo = bunbo*(i+1)%mod
    bunshi = bunshi*(n-i)%mod
  return (bunshi*pow(bunbo,mod-2,mod))%mod
mod = 10**9+7
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]

#bisect.bisect_left(list,key)はlistのなかでkey未満の数字がいくつあるかを返す
#bisect.bisect_right(list, key)はlistのなかでkey以下の数字がいくつあるかを返す
#これを応用することで
#len(list) - bisect.bisect_left(list,key)はlistのなかでkey以上の数字がいくつあるかを返す
#len(list) - bisect.bisect_right(list,key)はlistのなかでkeyより大きい数字がいくつあるかを返す
#これらを使うときはあらかじめlistをソートしておくこと！
n,m,k = MI()
a = deque(LI())
b = deque(LI())
ans = 0
while k > 0 and len(a) + len(b) > 0:
    if len(a) > 0:
        book = a.popleft()
    if len(a) == 0:
        book = 10**10
    if len(b) > 0:
        book2 = b.popleft()
    if len(b) == 0:
        book2 = 10**10
    if book < book2:
        k -= book
        if k > 0:
            ans += 1
    if book > book2
        k -= book2
        if k > 0:
            ans += 1
print(ans)

Submission status: Runtime Error

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

# print(a)
# print(b)

c = a + b
# print(c)
c.sort()
# print(c)

for i in range(len(c)):
    if k < 0:
        print(i-1)
        exit()
    else:
        k -= c[i]
print(len(c))

Submission status: Runtime Error

Solution code:
from bisect import bisect_right

N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
#a,bの累積和
a_sum = [0]
b_sum = [0]
for i in range(N):
    a_sum.append(a_sum[i]+a[i])
for i in range(M):
    b_sum.append(b_sum[i]+b[i])

ans = 0
#Aについて0-N冊読む場合の全探索
for i in range(N+1):
    cntA = i #Aをi冊読む
    rest = K - a_sum[i]#残り時間rest分
    if rest < 0:
        break
    cntB = bisect_right(b_sum,rest)-1 #Bで読むことができる冊数を二分探索で求める
    ans = max(ans,cntA + cntB)
    print(ans)
print(ans)

Submission status: Runtime Error

Solution code:
from bisect import bisect_right

n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
#a,bの累積和
a_sum = [0]
for i in range(n):
    a_sum.append(a_sum[i]+a[i])
b_sum = [0]
for i in range(n):
    b_sum.append(b_sum[i]+b[i])

ans = 0
#Aについて0-N冊読む場合の全探索
for i in range(n+1):
    cntA = i #Aをi冊読む
    rest = k - a_sum[i]#残り時間rest分
    if rest < 0:
        break
    cntB = bisect_right(b_sum,rest)-1 #Bで読むことができる冊数を二分探索で求める
    ans = max(ans,cntA + cntB)
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()))

cnt = 0
t = 0
x = 0
y = 0
for i in range(N + M):
    if x == N:
        t = t + B[y]
        y += 1
        cnt += 1
        if t > K:
            print(cnt - 1)
            exit()
    elif y == M:
        t = t + A[x]
        x += 1
        cnt += 1
        if t > K:
            print(cnt - 1)
            exit()
    else:
        t = t + min(A[x], B[y])
        if A[x] != B[y]:
            if A[x] == min(A[x],B[y]):
                x += 1
            elif B[y] == min(A[x],B[y]):
                y += 1
        else:
            a = x
            b = y
            while A[a] == B[b]:
                a += 1
                b += 1
            if A[a] == min(A[a],B[b]):
                x += 1
            elif B[b] == min(A[a],B[b]):
                y += 1
        cnt += 1
        if t > K:
            print(cnt-1)
            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()))

cnt = 0
t = 0
x = 0
y = 0
for i in range(N + M):
    if x == N:
        t = t + B[y]
        y += 1
        cnt += 1
        if t > K:
            print(cnt - 1)
            exit()
    elif y == M:
        t = t + A[x]
        x += 1
        cnt += 1
        if t > K:
            print(cnt - 1)
            exit()
    else:
        t = t + min(A[x], B[y])
        if A[x] != B[y]:
            if A[x] == min(A[x],B[y]):
                x += 1
            elif B[y] == min(A[x],B[y]):
                y += 1
        else:
            a = x
            b = y
            while(A[a] == B[b]):
                a += 1
                b += 1
            if A[a] == min(A[a],B[b]):
                x += 1
            elif B[b] == min(A[a],B[b]):
                y += 1
        cnt += 1
        if t > K:
            print(cnt-1)
            exit()

print(N + M)

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

def make_sumlist(book_list):
    sumnum=0
    container=[0]
    for i in book_list:
        container.append(sumnum+i)
        sumnum+=i
    return container

total_a=make_sumlist(a)
total_b=make_sumlist(b)

# print(n,m,k)
# print(total_a)
# print(total_b)


#r個読めるか
def readable(r):
    #全部読んでも無理
    if r>n+m:
        return False
    
    max_book=100000000000
    for a_n in range(max(0,r-m),min(n,r)+1):
        b_n=r-a_n
        # print(a_n,b_n)
        book_sum=total_a[a_n]+total_b[b_n]
        # print(book_sum)
        max_book=min(max_book,book_sum)
    if max_book<=k:
        return True
    return False

readable(4)


def nibuntansaku(start,end):
    if start==end:
        return start
    middle=(start+end)//2
    if readable(middle):
        start=middle
    else:
        end=middle-1
    return nibuntansaku(start,end)

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

time = 0
cont_a = 0
cont_b = 0

while time <= k:
    if a[cont_a] > b[cont_b]:
        if a[cont_a] < k:
            time += a[cont_a]
            cont_a += 1
        else:
            break
    else:
        if b[cont_b] < k:
            time += b[cont_b]
            cont_b += 1
        else:
            break
print(cont_a + cont_b)

Submission status: Runtime Error

Solution code:
n, m, k = map(int, input().split())
a = list(input().split())
b = list(input().split())
total = 0
book = 0
while total < k:
    if int(a[0]) < int(b[0]):
        total += int(a.pop(0))
        book += 1
    else:
        total += int(b.pop(0))
        book += 1
print(book - 1 if total > k else book)

Submission status: Runtime Error

Solution code:
n, m, k = map(int, input().split())
a = list(input().split())
b = list(input().split())
total = 0
book = 0
while total < k:
    if a[0] < b[0]:
        total += a.pop(0)
        book += 1
    else:
        total += b.pop(0)
        book += 1
print(book)

Submission status: Runtime Error

Solution code:
inp = input()
n, m, k = inp.split(' ')
a_inp = input()
a = a_inp.split(' ')
b_inp = input()
b = b_inp.split(' ')

a = [int(n) for n in a]
b = [int(n) for n in b]

total_book = 0
total_time = 0
tmp_total = 0

c = b.copy() if len(a) > len(b) else a.copy()

i = 0
while True:
    if a[0] < b[0]:
        total_time += a[0]
        a.pop(0)
    else:
        total_time += b[0]
        b.pop(0)

    if total_time >= int(k):
        break
    else:
        total_book += 1
    if len(a) == 0 or len(b) == 0:
        break
    i += 1


c = b.copy() if len(a) == 0 else a.copy()

if total_time > int(k):
    print(total_book)
    eixt()

for i in range(len(c)):
    total_time += c[i]
    if total_time >= int(k):
        break
    else:
        total_book += 1


print(total_book)

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
a = 0
b = 0
while time <= K:
  if A[a] <= B[b] and time+A[a] <= K:
    time += A[a]
    a += 1
  elif A[a] > B[b] and time+B[b] <= K:
    time += B[b]
    b += 1
print(time)

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()))
Sum = 0
Al = [0]
Bl = [0]
for i in range(N):
    Sum += A[i]
    Al.append(Sum)
Sum = 0
for j in range(M):
    Sum += B[i]
    Bl.append(Sum)
ans, j = 0, M
for i in range(N+1):
    if Al[i] > K:
        break
    while Bl[j] > K - Al[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.append(k+1)
    b.append(k+1)
    ia = 0
    ib = 0
    count = 0

    for i in range(n + m + 1):
        if (a[ia] < b[ib]):
            if(a[ia] > k):
                print(count)
                break
            else:
                k -= a[ia]
                ia += 1
                count += 1
        else:
            if(b[ib] > k):
                print(count)
                break
            else:
                k -= b[ib]
                ib += 1
                count += 1

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

number=0
time=0
x=0
y=0

while True:
    if time>k:
        number-=1
        break
    elif a[x]<b[y]:
        number+=1
        time+=a[x]
        x+=1
    else:
        number+=1
        time+=b[y]
        y+=1
print(number)

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_sum = 0
b_sum = sum(b_list)

j = m
best=0
for i, a in enumerate(a_list):
  a_sum+=a
  if a_sum>k:
    break
  while ((a_sum + b_sum) > k) & (j>=0):
    b_sum-=b_list[j]
    j-=1
    
  best = max(best,i+j+2)
      
  
    
print(best)

Submission status: Runtime Error

Solution code:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=a+b
ans=0
t=0
if sum(c)<=k:
    print(n+m)
else:
    while t<=k:
        if a[0]>=b[0]: 
            t+=b[0]
            if t<=k:
                ans+=1
                b.remove(b[0])
        else:
            t+=a[0]
            if t<=k:
                ans+=1
                a.remove(a[0])
print(ans)

Submission status: Runtime Error

Solution code:
B = [0]
N, M, K = list(map(int, input().split()))
A = deque(map(int, input().split()))
A.appendleft(0)
B.extend(list(map(int, input().split())))

a = 0
for i in range(N+1):
    a += A[i]
    if a < K:
        max_a = i
        
b = 0
for j in range(M+1):
    b += B[j]
    #print(j, b, K)
    if b < K:
        max_b = j
        
result = [[0] * (max_a+1) for _ in range(max_b+1)]
a = 0
rest = 10^9

for i in range(max_a+1):
    a += A.popleft()
    rest = K - a
    _rest = rest
    for j in range(max_b+1):
        _rest -= B[j]
        if _rest >= 0:
            result[j][i] = i + j
print(max(list(chain(*result))))

Submission status: Runtime Error

Solution code:
import numpy as np
n,m,k=map(int,input().split())
A=list(map(int, input().split()))
B=list(map(int, input().split()))
ans=0
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])
for i in range(n+1):
    if k<a[i]:
        break
    j=m
    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()))
aa = [0]
bb = [0]
for i in a:
    aa.append(aa[-1]+i)
for i in b:
    bb.append(bb[-1]+i)
for i in range(n+1):
    if aa[i] > k:
        break
    for j in range(m+1):
        if aa[i]+bb[j] <= k:
            tmp = i+j
        else:
            break
    ans = max(ans, tmp)
print(ans)

Submission status: Runtime Error

Solution code:
3 4 730
60 90 120
80 150 80 150

Submission status: Runtime Error

Solution code:
def solve():
    n,m,k = list(map(int,input().split()))
    arr = list(map(int,input().split()))
    arr1 = list(map(int,input().split()))
    count = 0
    trackLoop = 1
    trackCount = 0
    while trackCount<k:
        if trackCount==k:
            return count+1
        if len(arr)>0 and arr[0]<arr1[0]:
            trackCount+=arr.pop(0)
        else:
            if len(arr1)>0:
                trackCount+=arr1.pop(0)
            else:
                trackCount+=arr.pop(0)
        if trackCount==k:
            return count+1
        trackLoop+=1
        count+=1
        
    return count-1
    
print(solve())