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:
import sys
from itertools import accumulate
import operator as op
input = sys.stdin.readline

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

a = list(accumulate(A,op.add))
b = list(accumulate(B,op.add))
ans = 0
j = m-1
for i in range(n+1):
    if a[i]>k:
        break
    while b[j]>k-a[i] and j>=0:
        j-=1
    ans=max(ans,i+j+2)
print(ans)

Submission status: Runtime Error

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

stackA = [int(x) for x in input().split()]
stackB = [int(x) for x in input().split()]

books = 0

while True:
    if len(stackB) == 0:
        if len(stackA) == 0:
            break

        K -= stackA.pop(0)

    elif len(stackA) == 0:
        K -= stackB.pop(0)

    else:
        test = 0
        while stackA[test] == stackB[test]:
            test += 1
          
        if stackA[test] > stackB[test]:
            K -= stackB.pop(0)

        else:
            K -= stackA.pop(0)        

    if K < 0:
        break
        
    books += 1

print(books)

Submission status: Runtime Error

Solution code:
import sys
from itertools import accumulate
import operator as op
input = sys.stdin.readline

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

a = list(accumulate(A,op.add))
b = list(accumulate(B,op.add))
ans = 0
j = m-1
for i in range(n):
    if a[i]>k:
        break
    while b[j]>k-a[i]:
        j-=1
    ans=max(ans,i+j+2)
print(ans)

Submission status: Runtime Error

Solution code:
import sys
from itertools import accumulate
import operator as op
input = sys.stdin.readline

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

a = list(accumulate(A,op.add))
b = list(accumulate(B,op.add))

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

Submission status: Runtime Error

Solution code:
n,m,l = map(int,input().split(" "))
Ns = input().split(" ")
N = [int (n) for n in Ns]
Ms = input().split(" ")
M = [int(n) for n in Ms]
#print(n,m,l)
#print(N,M)
i = 0
j = 0
total = 0
cnt = 0
while total <= l:
  #print(i,j,total,cnt)
  if  i == n and j == m:
    break
  elif i < n and j == m:
    if total + N[i] <= l:
      total = total + N[i]
      i = i+1
      cnt = cnt + 1
    else:
      break
  elif i == n and j < m:
    if total + M[i] <= l:
      total = total + M[j]
      j = j+1
      cnt = cnt +1
    else:
      break
  elif i < n and j < m and (total+N[i] <= l or total+M[j] <= l):
    if N[i] <= M[j]:
      total = total + N[i]
      i = i+1
      cnt = cnt +1
    elif N[i] > M[j]:
      total = total + M[j]
      j = j+1
      cnt = cnt +1
  else:
    break
print(cnt)#,i,j,total,n,m,l)

Submission status: Runtime Error

Solution code:
from itertools import accumulate
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ans = 0
SA,SB = list(accumulate(A)),list(accumulate(B))
if SA[-1] <= K:
  ans = N
if SB[-1] <= K:
  ans = max(ans,M)
j = M-1
for i in range(N):
  if SA[i] > K:
    break
  while SB[j] > K-SA[i]:
    j -= 1
    if j == -1:
      break
  ans = max(ans,i+j+2)
j = N-1
for i in range(M):
  if SB[i] > K:
    break
  while SA[j] > K-SB[i]:
    j -= 1
    if j == -1:
      break
  ans = max(ans,i+j+2)
print(ans)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
N,M,K = map(int, input().split())
Nnums = list(map(int, input().split()))
Mnums = list(map(int, input().split()))

Nmax=len(Nnums)
Mmax=len(Mnums)
Nsum=0
Ncnt=0

#Nのみの場合に何冊読めるか
for Ni,Nl in enumerate(Nnums):
  Nsum += Nl
  Ncnt = Ni
  if Nsum > K:
    Nsum -= Nl
    Ncnt = Ni-1
    break
    
chkSum = Nsum
chkCnt = Ncnt + 1
AnsCnt = Ncnt + 1
  
#Mを組み入れて最大数を探す
for Mi,Ml in enumerate(Mnums):
  chkSum += Ml
  chkCnt += 1
  if (chkSum > K):
    if 
    while chkSum > K:
      if not Ncnt < 0:
        chkSum -= Nnums[Ncnt]
        chkCnt -= 1
        Ncnt -= 1
      elif:
        break
  
  if (AnsCnt < chkCnt):
    AnsCnt = chkCnt
  
  if (Ncnt < 0):
    break

print(AnsCnt)

Submission status: Runtime Error

Solution code:
from itertools import accumulate
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ans = 0
SA,SB = list(accumulate(A)),list(accumulate(B))
j = M-1
for i in range(N):
  if SA[i] > K:
    break
  while SB[j] > K-SA[i]:
    j -= 1
  ans = max(ans,i+j+2)
print(ans)

Submission status: Runtime Error

Solution code:
from itertools import accumulate
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ans = 0
SA,SB = list(accumulate(A)),list(accumulate(B))
if SA[-1] <= K:
  ans = N
if SB[-1] <= K:
  ans = max(ans,M)
j = M-1
for i in range(N):
  if SA[i] > K:
    break
  while SB[j] > K-SA[i]:
    j -= 1
  ans = max(ans,i+j+2)
print(ans)

Submission status: Runtime Error

Solution code:
a,b,t=map(int,input().split())
l1=list(map(int,input().split()))
l2=list(map(int,input().split()))
s=0
c=0
while t>s:
    if l1[0]>l2[0]:
        s+=l2.pop(0)
    else:
        s+=l1.pop(0)
    c+=1
if s>t:
    print(c-1)
else:
    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()))
i=0
kk=k
mx=0
while i<n and a[i]<=k:
    k-=a[i]
    i+=1
    mx+=1
j=0
while j<m and b[j]<=k:
    k-=b[j]
    j+=1
    mx+=1
cou=mx
while i>=0 and j<m:
    k+=a[i]
    i-=1
    cou-=1
    while j<m and b[j]<=k:
        j+=1
        k-=b[j]
        cou+=1
    mx=max(cou,mx)
print(mx)

Submission status: Runtime Error

Solution code:
from itertools import accumulate
from bisect import bisect_left
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ans = 0
SA,SB = list(accumulate(A)),list(accumulate(B))
if SA[-1] <= K:
  ans = N
if SB[-1] <= K:
  ans = max(ans,M)

for i in range(N):
  if SA[i] > K:
    break
  b = bisect_left(SB,K-SA[i])
  if b >= M:
    b -= 1
  for j in range(b,-1,-1):
    if SA[i]+SB[j] <= K:
      ans = max(ans,i+j+2)
      break
for j in range(M):
  if SB[i] > K:
    break
  b = bisect_left(SA,K-SB[i])
  if b >= N:
    b -= 1
  for j in range(b,-1,-1):
    if SB[i]+SA[j] <= K:
      ans = max(ans,i+j+2)
      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()))
i=0
kk=k
mx=0
while a[i]<=k:
    k-=a[i]
    i+=1
    mx+=1
j=0
while b[j]<=k:
    k-=b[j]
    j+=1
    mx+=1
cou=mx
while i>=0 and j<m:
    k+=a[i]
    i-=1
    cou-=1
    while j<m and b[j]<=k:
        j+=1
        k-=b[j]
        cou+=1
    mx=max(cou,mx)
print(mx)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(2147483647)

N, M, K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
Asum = []
Bsum = []
count = 0
for p in A:
    count += p
    Asum.append(count)
count = 0
for p in B:
    count += p
    Bsum.append(count)
best = 0
Blast = M-1
for t in range(N):
    if Asum(t) > K:
        break
    if best < t+1:
        best=t+1
    for s in reversed(range(0,Blast+1)):
        if Asum[t]+Bsum[s]<=K:
            if best < t+1+s+1:
                best=t+1+s+1
            Blast = s
            break
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()))
A=[0]
for i in range(n):
  A.append(a[i])
B=[0]
for i in range(m):
  B.append(b[i])
ans=0
j=m
for i in range(n+1):
  while B[j]>(k-A[i]):
    j-=1
  ans=max(ans,i+j)
print(ans)

Submission status: Runtime Error

Solution code:
import sys
import math
import heapq
from collections import defaultdict, deque
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
def r():
    return int(input())
def rm():
    return map(int,input().split())
def rl():
    return list(map(int,input().split()))

'''C Tsundoku'''
n,m,k=rm()
a=rl()
b=rl()
c=[0]*(n+1)
d=[0]*(b+1)
for i in range(n):
    c[i+1]=c[i]+a[i]
for i in range(m):
    d[i+1]=d[i]+b[i]
ans=0;j=m
for i in range(n+1):
    if c[i]>k:
        break
    while c[i]+d[j]>k:
        j-=1
    ans=max(ans,i+j)
print(ans)

Submission status: Runtime Error

Solution code:
import sys
import math
import heapq
from collections import defaultdict, deque
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
def r():
    return int(input())
def rm():
    return map(int,input().split())
def rl():
    return list(map(int,input().split()))

'''C Tsundoku'''
n,m,k=rm()
a=rl()
b=rl()
c=[0]*(n+1)
d=[0]*(b+1)
for i in range(n):
    c[i+1]=c[i]+a[i]
for i in range(m):
    d[i+1]=d[i]+b[i]
ans=0;j=m
for i in range(n+1):
    if c[i]>k:
        break
    while c[i]+c[j]>k:
        j-=1
    ans=max(ans,i+j)
print(ans)

Submission status: Runtime Error

Solution code:
# D - Sum of Divisors
from numba import njit


@njit
def solve(N):
    res = 0
    for a in range(1, N + 1):
        for b in range(1, N // a + 1):
            res += a * b
    return res


def main():
    N = int(input())
    print(solve(N))


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
from collections import deque

def solve():
    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 = 0
    j = M

    for i in range(len(A)):
        if a[i] > K:
            break
        while b[j] < K - a[i]:
            j -= 1
        ans = max(ans, i+j)
    
    print(ans)
            
solve()

Submission status: Runtime Error

Solution code:
from collections import deque

def solve():
    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 = 0
    j = M

    for i in range(len(A)):
        if a[i] > K:
            break
        while b[j] < K - a[i]:
            j -= 1
        ans = max(ans, i+j)
    
    print(ans)
            
solve()

Submission status: Runtime Error

Solution code:
@profile
def main():
    from numpy import cumsum
    n, m, k = list(map(int, input().split()))
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    A = cumsum([0] + A)
    B = cumsum([0] + B)
    n_read = 0
    b_tail = B[-1]
    for i, a in enumerate(A):
        if a > k:
            break
        j = m
        if b_tail + a > k:
            for j, b in enumerate(B):
                if a + b > k:
                    break
        n_read = max(n_read, i + j)
    print(n_read)
main()

Submission status: Runtime Error

Solution code:
from itertools import accumulate
from bisect import bisect_left

n, m, k = map(int, input().split())
a = [0] + list(accumulate(list(map(int, input().split()))))
b = [0] + list(accumulate(list(map(int, input().split()))))
ans = 0

for i in range(n + 1):
    if a[i] + b[bisect_left(b, k - a[i])] <= k:
        ans = max(ans, i + bisect_left(b, k - a[i]))
    
print(ans)

Submission status: Runtime Error

Solution code:
n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
SA = [A[0]]
SB = [B[0]]

if A[0] > k and B[0] > k:
    print(0)
    exit()

for i in range(n-1):
    if SA[i] + A[i+1] > k:
        break
    SA.append(SA[i] + A[i+1])
for i in range(m-1):
    if SB[i] + B[i+1] > k:
        break
    SB.append(SA[i] + B[i+1])

ans = max(len(SA), len(SB))
for i in range(len(SA)):
    c = i
    for j in range(i, len(SB)):
        if SA[len(SA)-i-1] + SB[j] > k:
            break
        c += 1
    ans = max(ans, len(SA) + c)
print(ans)

Submission status: Runtime Error

Solution code:
from itertools import accumulate
from bisect import bisect
def main():
    n, m, k = map(int, input().split())
    a = tuple(map(int, input().split()))
    b = tuple(map(int, input().split()))

    aa = tuple(accumulate(a))
    ba = tuple(accumulate(b))
    r = 0
    for i1 in range(n):
        if aa[i1] > k:
            break
        else:
            t = bisect(ba, k - aa[i1])
            r = max(r, i1 + 1 + t)
    for j1 in range(m):
        if ba[j1] > k:
            break
        else:
            t = bisect(aa, k - ba[i1])
            r = max(r, j1 + 1 + t)
    print(r)
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from collections import deque
import numpy


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

    a_cumsum = numpy.cumsum(a)
    b_cumsum = numpy.cumsum(b)

    a_i = len(a) - 1
    b_i = len(b) - 1
    while k <= a_cumsum[a_i] + b_cumsum[b_i]:
        if a_i == -1 and b_i == -2:
            break
        elif a_i == -1:
            b_i -= 1
        elif b_i == -1:
            a_i -= 1
        elif a[a_i] < b[b_i]:
            b_i -= 1
        else:
            a_i -= 1

    print(a_i + b_i + 3)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

a, 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:
#import 
#=input()
#=int(input())
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
#=[list(map(int,input().split())) for _ in range()]

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

Submission status: Runtime Error

Solution code:
1 N, M, K = map(int, input().split())
2 A = list(map(int, input().split()))
3 B = list(map(int, input().split()))
4
5 a, b = [0], [0]
6 for i in range(N):
7 　　a.append(a[i] + A[i])
8 for i in range(M):
9 　　b.append(b[i] + B[i])
10
11 ans, j = 0, M
12 for i in range(N + 1):
13 　　if a[i] > K:
14 　　　　break
15　　 while b[j] > K - a[i]:
16 　　　　j -= 1
17 　　ans = max(ans, i + j)
18 print(ans)

Submission status: Runtime Error

Solution code:
1 N, M, K = map(int, input().split())
2 A = list(map(int, input().split()))
3 B = list(map(int, input().split()))
4
5 a, b = [0], [0]
6 for i in range(N):
7 	a.append(a[i] + A[i])
8 for i in range(M):
9 	b.append(b[i] + B[i])
10
11 ans, j = 0, M
12 for i in range(N + 1):
13 　　if a[i] > K:
14 		　break
15 　while b[j] > K - a[i]:
16 　　j -= 1
17 　ans = max(ans, i + j)
18 print(ans)

Submission status: Runtime Error

Solution code:
n,m,l = map(int,input().split(" "))
Ns = input().split(" ")
N = [int (n) for n in Ns]
Ms = input().split(" ")
M = [int(n) for n in Ms]
#print(n,m,l)
#print(N,M)
i = 0
j = 0
total = 0
cnt = 0
while total <= l:
  if  N[i] <= M[j]:
    total = total + N[i]
    i = i+1
    cnt = cnt +1
  else:
    total = total + M[j]
    j = j+1
    cnt = cnt +1
print(cnt-1)

Submission status: Runtime Error

Solution code:
from bisect import bisect_left,bisect_right
n,m,k=map(int,input().split())
arr1=list(map(int,input().split()))
arr2=list(map(int,input().split()))
for i in range(1,n):
    arr1[i]=arr1[i]+arr1[i-1]
for i in range(1,m):
    arr2[i]=arr2[i]+arr2[i-1]
ma=0
for i in range(n):
    c=k-arr1[i]
    ind=bisect_right(arr2,c)
    if arr2[ind]<=c:
        ma=max(ma,ind+i+1)
print(ma)

Submission status: Runtime Error

Solution code:
n,m,l = map(int,input().split(" "))
Ns = input().split(" ")
N = [int (n) for n in Ns]
Ms = input().split(" ")
M = [int(n) for n in Ms]
#print(n,m,l)
#print(N,M)
i = 0
j = 0
total = 0
cnt = 0
while total <= l:
  if  N[i] <= M[j]:
    total = total + N[i]
    i = i+1
    cnt = cnt +1
  else:
    total = total + M[j]
    j = j+1
    cnt = cnt +1
print(cnt)

Submission status: Runtime Error

Solution code:
from sys import stdin

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

A2 = []
B2 = []
temp = 0
for a in A:
    temp += a
    A2.append(temp)
temp = 0
for b in B:
    temp += b
    B2.append(temp)

ans = 0
j = M-1

for i in range(N):
    if A2[i] > K:
        ans = max(ans,i+1)
        break
    while A2[i]+B2[j] > K:
        j -= 1
    ans = max(ans,i+j+2)

print(ans)

Submission status: Runtime Error

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

A = [0]
B = [0]

A += [int(x) for x in input().split()]
B += [int(x) for x in input().split()]

total = 0
ans = 0

if A[1] > K and B[1] > K:
    ans = 0
else:
    for j in range(M+1):
        if total + B[j] <= K:
            total += B[j]
            j_max = j
            ans = j_max
        else:
            break
    for i in range(1,N + 1):
        if (total + A[i]) <= K:
            total = total + A[i]
            ans = ans + 1
        else:
            j_tmp = j_max
            while (total + A[i]) > K:
                total = total + A[i] - B[j_tmp]
                j_tmp -= 1
                if j_tmp == 0:
                    break
            j_max = j_tmp
            
        ans = max(ans,i+j_max)

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

b_sum = 0
for i in range(M):
    b_sum += B[i]
    if b_sum > K:
        b_sum -= B[i]
        j = i - 1
        break
result = j + 1

a_sum = 0
for i in range(N):
    a_sum += A[i]
    if a_sum > K:
        break
    while a_sum + b_sum > K:
        b_sum -= B[j]
        j -= 1
    result = max(result, (i + 1) + (j + 1))
print(result)

Submission status: Runtime Error

Solution code:
from sys import stdin

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

A2 = []
B2 = []
temp = 0
for a in A:
    temp += a
    A2.append(temp)
temp = 0
for b in B:
    temp += b
    B2.append(temp)

ans = 0
j = M-1

for i in range(N):
    if A2[i] > K:
        ans = max(ans,i-1)
        break
    while A2[i]+B2[j] > K:
        j -= 1
    ans = max(ans,i+j+2)

print(ans)

Submission status: Runtime Error

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

A = input()
a = A.split()
B = input()
b = B.split()
result = 0 
count = 0
r = ((M + N) - 1) / 2
for i in range(M + N ):
 count += 1
 result += int(a[i-1])
 if result > K:
  break
 else:
  count += 1
  result += int(b[i-1]) 
  if result > K:
   break
if i == r:
  count += 1
  
rc = count - 1
print(rc)

Submission status: Runtime Error

Solution code:
a,n,m = input(), input(), input()
first = a.split(" ")
N = n.split(" ")
M = m.split(" ")
overflow = 0
for i in N:
    if int(i) >= 10**9:
        overflow = 1
        break
        
for i in M:
    if int(i) >= 10**9:
        overflow = 1
        break
if int(first[0]) >= 200000 or int(first[1]) >= 200000:
    overflow = 1
if int(first[2]) >= 10**9:
    overflow = 1
         
if overflow == 0:
    totaltime = 0
    count = 0
    for i in range(int(first[1]) + int(first[0])):
      if int(N[0]) < int(M[0]):
        totaltime += int(N[0])
        N.remove(N[0])
        count += 1
      elif int(M[0]) < int(N[0]):
        totaltime += int(M[0])
        M.remove(M[0])
        count += 1
      if totaltime + min(int(N[0]),int(M[0])) > int(first[2]):
          break
    print(count)
else:
    print(0)

Submission status: Runtime Error

Solution code:
N, M, K = map(int, input().split())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
timeA, timeB = 0, 0
numA, numB = 0, 0
for i in range(N):
    if timeA + A[i] <= K:
        numA += 1
        timeA += A[i]
    else:
        break
for i in range(M):
    if timeB + B[i] <= K - timeA:
        numB += 1
        timeB += B[i]
    else:
        break
ans = numA + numB
t = numA
j = numB
for i in reversed(range(numA)):
    t -= 1
    timeA -= A[i]
    while j < M:
        if timeB + B[j] <= K - timeA:
            numB += 1
            timeB += B[i]
            j += 1
        else:
            break
    ans = max(ans, t + numB)
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()))
c = [0]
d = [0]
for i in range(n):
    c.append(a[i]+c[i])
for i in range(m):
    d.append(b[i]+d[i])
e = 0
for i in range(n+1):
    if a[i] > k:
        break;
    while b[m] > k-a[i]:
        m -= 1
    e = max(e, i+m)
print(e)

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]
d = [0]
for i in range(n):
    c.append(a[i]+c[i])
for i in range)m:
    d.append(b[i]+d[i])
e = 0
for i in range(n+1):
    if a[i] > k:
        break;
    while b[m] > k-a[i]:
        m -= 1
    e = max(e, i+m)
print(e)

Submission status: Runtime Error

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

A = [0]
B = [0]

A += [int(x) for x in input().split()]
B += [int(x) for x in input().split()]

total = 0
ans = 0

if A[1] > K and B[1] > K:
    ans = 0
else:
    for j in range(M+1):
        if total + B[j] <= K:
            total += B[j]
            j_max = j
            ans = j_max
        else:
            break
    for i in range(1,N + 1):
        if (total + A[i]) <= K:
            total = total + A[i]
            ans = ans + 1
        else:
            while (total + A[i]) > K:
                total = total - B[j_max]
                j_max -= 1
        ans = max(ans,i+j_max)

print(ans)

Submission status: Runtime Error

Solution code:
N, M, K = map(int, input().split())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
timeA, timeB = 0, 0
numA, numB = 0, 0
for i in range(N):
    if timeA + A[i] <= K:
        numA += 1
        timeA += A[i]
    else:
        break
for i in range(M):
    if timeB + B[i] <= K - timeA:
        numB += 1
        timeB += B[i]
    else:
        break
ans = numA + numB
t = numA
j = numB
for i in reversed(range(numA)):
    t -= 1
    timeA -= A[i]
    while j < M:
        if timeB + B[j] <= K - timeA:
            numB += 1
            timeB += B[i]
        else:
            break
    ans = max(ans, t + numB)
print(ans)

Submission status: Runtime Error

Solution code:
import logging

logging.basicConfig(level=logging.INFO)
logging.info('info')


def main():
    N, M, K = map(int, input().split())
    A_list = list(map(int, input().split()))
    B_list = list(map(int, input().split()))
    logging.info("hello")

    a = [0]
    b = [0]

    for i in range(N):
        a.append(a[i] + A_list[i])

    for i in range(M):
        b.append(b[i] + B_list[i])

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

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
N, M, K = map(int, input().split())
times_a = list(map(int, input().split()))
times_b = list(map(int, input().split()))
read_time = 0
read_time_a = [0]
read_time_b = [0]
for i in range(len(times_a)):
    read_time_a.append(read_time_a[i]+times_a[i])
for i in range(len(times_b)):
    read_time_b.append(read_time_b[i]+times_b[i])
count = 0
for i in range(N+1):
    t = read_time_a[i]
    l = 0
    r = len(read_time_b)
    while l + 1 < r:
        c = (l + r) // 2
        if t + read_time_b[c] <= K:
            l = c
        else:
            r = c
    if read_time_a[i] + read_time_b[l] <= K:
        ans = max(ans, i + l)
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, bb = [0], [0]
for i in range(n):
	aa.append(aa[i]+a[i])
 
for i in range(m):
	bb.append(b[i]+bb[i])
 
 
ans, i = 0, m
for j in range(n+1):
	if aa[j] > k:
		break
	while b[i] > k-aa[j]:
		j -= 1
 
	ans = max(ans, i+j)
 
 
print(ans)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF = 10**20
def main():
    N,M,K=mi()
    A=[0]+list(mi())
    B=[0]+list(mi())

    v = [0]*(N+1)
    u = [0]*(M+1)

    for i in range(N):
        v[i+1] = A[i+1] + v[i]
        
    for i in range(M):
        u[i+1] = B[i+1] + u[i]

    # print(u,v)
    ans = 0
    for i in range(M+1):
        if K-u[i] < 0: continue
        j = bisect.bisect_left(v,K-u[i])

        if j == 0 and K-u[i] < A[0]: continue
        
        if j<len(v) and v[j] != K-u[i]:
            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(input().split())
B = list(input().split())
A = [int(x) for x in A]
B = [int(x) for x in B]
tmp = 0

if min(A)>K or min(B)>K:
    print(0)
    exit()

for i in range(N):
    if K-A[i] >= 0:
        tmp +=1
        K -= A[i]
    else:
        break
ans = [0]*tmp
Kmin = K

for h in range(tmp):
    ans[h] = tmp - h
    for j in range(M):
        if K-B[j] >= 0:
            ans[h] += 1
            K -= B[j]
    K = Kmin + A[tmp-1-h]
    Kmin = K

print(max(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, bb = [0], [0]
for i in range(n):
	aa.append(aa[i]+a[i])

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


ans, i = 0, m
for j in range(n+1):
	if aa[j] > k:
		break
	while b[i] > k-aa[j]:
		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()))
if sum(a)+sum(b)<k:
    ans=m+n
else:
    numa=[0]
    numb=[0]
    for i in range(n):
        numa.append(numa[-1]+a[i])
    for j in range(m):
        numb.append(numb[-1]+b[i])
    ans=0
    for i in range(n+1):
        if numa[i]>k:
            break
        while numb[m]>k-numa[i]:
            m-=1
        ans=max(ans,i+m)
print(ans)

Submission status: Runtime Error

Solution code:
from itertools import accumulate
from bisect import bisect_left

n,m,k=map(int,input().split())
a=accumulate([0]+list(map(int,input().split())))
b=accumulate([0]+list(map(int,input().split())))
mx=0
for i in range(n+1):
  idx=bisect_left(max(k-a[i],0),b)
  mx=max(mx,i+idx)
print(mx)

Submission status: Runtime Error

Solution code:
def can(x):
    i = min(n,x)
    end = min(m,i)
    t = a[i]+b[x-i]
    for k in range(x-i,end+1):
        t = min(t, a[i]+b[k])
        i -= 1
    if t<=k:
        return True
    else:
        return False

n,m,k=map(int,input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
a = [0]+a
for i in range(1,n+1):
    a[i] += a[i-1]
b = [0]+b
for i in range(1,m+1):
    b[i] += b[i-1]

lo = 0
hi = n+m
while lo<hi:
    mid=lo+((hi-lo+1)>>1)
    if can(mid):
        lo=mid
    else:
        hi = mid-1
print(lo)

Submission status: Runtime Error

Solution code:
from sys import exit
import copy
# import numpy as np
from collections import deque

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

cnt=0

a_sum=[0]
b_sum=[0]

a.insert(0, 0)
b.insert(0, 0)


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

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


for i in range(n+1):
    for j in range(m+1):
        if a_sum[i] + b_sum[j] <= k:
            pass
        else:
            if a_sum[i] + b_sum[j-1] <= k:
                cnt=max(cnt, i + j - 1)
            break
    else:
        if a_sum[i] + b_sum[j] <= k:
            cnt=max(cnt, i + j)
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()))
     
    Asum = [0]
    Bsum = [0]
    atemp = 0
    btemp = 0
    for i in range(N):
        atemp += A[i]
        Asum.append(atemp)
    for i in range(M):
        btemp += B[i]
        Bsum.append(btemp)
     
    ans = 0
    j = M
    for i in range(N+1):
        if Asum[i] > K:
            break
        while Asum[i] + Bsum[j] > K:
            j -= 1
        ans = max(ans, i+j)
     
    print(ans)