Problem:


Score : 300 points

Problem Statement

We have two desks: A and B. Desk A has a vertical stack of N books on it, and Desk B similarly has M books on it.

It takes us A_i minutes to read the i-th book from the top on Desk A (1 \leq i \leq N), and B_i minutes to read the i-th book from the top on Desk B (1 \leq i \leq M).

Consider the following action:

Choose a desk with a book remaining, read the topmost book on that desk, and remove it from the desk.

How many books can we read at most by repeating this action so that it takes us at most K minutes in total? We ignore the time it takes to do anything other than reading.

Constraints

1 \leq N, M \leq 200000

1 \leq K \leq 10^9

1 \leq A_i, B_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M K
A_1 A_2 \ldots A_N
B_1 B_2 \ldots B_M

Output

Print an integer representing the maximum number of books that can be read.

Sample Input 1

3 4 240
60 90 120
80 150 80 150

Sample Output 1

3

In this case, it takes us 60, 90, 120 minutes to read the 1-st, 2-nd, 3-rd books from the top on Desk A, and 80, 150, 80, 150 minutes to read the 1-st, 2-nd, 3-rd, 4-th books from the top on Desk B, respectively.

We can read three books in 230 minutes, as shown below, and this is the maximum number of books we can read within 240 minutes.

Read the topmost book on Desk A in 60 minutes, and remove that book from the desk.

Read the topmost book on Desk B in 80 minutes, and remove that book from the desk.

Read the topmost book on Desk A in 90 minutes, and remove that book from the desk.

Sample Input 2

3 4 730
60 90 120
80 150 80 150

Sample Output 2

7

Sample Input 3

5 4 1
1000000000 1000000000 1000000000 1000000000 1000000000
1000000000 1000000000 1000000000 1000000000

Sample Output 3

0

Watch out for integer overflows.



Sample input:
3 4 240
60 90 120
80 150 80 150


Sample output:
3

Submission status: Runtime Error

Solution code:
n,m,k = map(int,input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
A,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])
 
num,x = 0,m-1
A.pop(0)
B.pop(0)
 
for i in range(len(a)):
  if A[i] > k:
    break
  while A[i] + B[x] > k:
    x -= 1
  num = max(num, i + x + 2)
  
print(num)

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

num,x = 0,m-1
A.pop(0)
B.pop(0)

for i in range(n):
  if A[i] > k:
    break
  while A[i] + B[x] > k:
    x -= 1
  num = max(num, i + x + 2)
  
print(num)

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

num = 0
x = m - 1
A.pop(0)
B.pop(0)

for i in range(n):
  if A[i] > k:
    break
  while A[i] + B[x] > k:
    x -= 1
  num = max(num, i + x + 2)
  
print(num)

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

num = 0
x = m 

for i in range(len(A)+1):
  if A[i] > k:
    break
  while A[i] + B[x] > k:
    x -= 1
  num = max(num, i + x)
  
print(num)

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

num = 0
x = m 

for i in range(len(A)+1):
  if A[i] > k:
    break
  while A[i] + B[x] > k:
    x -= 1
  num = max(num, i + x )
  
print(num)

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

num = 0
x = m - 1
A.pop(0)
B.pop(0)

for i in range(len(A)):
  if A[i] > k:
    break
  while A[i] + B[x] > k:
    x -= 1
  num = max(num, i + x + 2)
  
print(num)

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,0
for i in range(N+1):
  if a[i]>K:
    break
  while b[j] <= K - a[i]:
    j += 1
  ans = max(ans, i+j-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,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,0
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:
# -*- coding: utf-8 -*-
"""
Created on Fri Sep 18 19:19:52 2020

@author: ezwry
"""

n,m,k=map(int,input().split())
alist=list(map(int,input().split()))
blist=list(map(int,input().split()))
ans=0

while 1:
    if alist==[] and blist==[]:
        print(ans)
        exit()
    elif not alist == [] and not blist == []:
        if alist[0]<=blist[0] and k>=alist[0]:
            k-=alist[0]
            alist.pop(0)
            ans+=1
        elif alist[0]>blist[0] and k>=blist[0]:
            k-=blist[0]
            blist.pop(0)
            ans+=1
        else:
            print(ans)
            exit()
    elif alist==[]:
        if blist[0]<=k:
            k-=blist[0]
            blist.pop(0)
        else:
            print(ans)
            exit()
    else:
        if alist[0]<=k:
            k-=blist[0]
            blist.pop(0)
        else:
            print(ans)
            exit()

Submission status: Runtime Error

Solution code:
#                               #
    # author : samars_diary #
    # 17-09-2020 │ 20:34:30 #
#                               #

import sys, os.path

if(os.path.exists('input.txt')):
    sys.stdin = open('input.txt',"r")
    #sys.stdout = open('output.txt',"w")

sys.setrecursionlimit(10 ** 5)

def mod(): return 10**9+7
def i(): return sys.stdin.readline().strip()
def ii(): return int(sys.stdin.readline())
def li(): return list(sys.stdin.readline().strip())
def mii(): return map(int, sys.stdin.readline().split())
def lii(): return list(map(int, sys.stdin.readline().strip().split()))

#print=sys.stdout.write

def solve():
    n,m,k=mii();d=0
    a=lii();b=lii();i=j=l=0
    while (i<n or j<m) and l!=-1:
        if i<n and a[i]<=b[j]:
            if a[i]<=k:
                k-=a[i];i+=1;d+=1
            else:
                l=-1
        else:
            if j<m:
                if b[j]<=k:
                    k-=b[j];j+=1;d+=1
                else:
                    l=-1
            else:
                l=-1
    print(d)
for _ in range(1):
    solve()

Submission status: Runtime Error

Solution code:
N = int(input())
import math
def getdiv(x):
    list = []
    for i in range(1,math.floor(math.sqrt(x))+1):
        if x%i==0 and (not i in list):
            list.append(i)
    if math.sqrt(x) == math.floor(math.sqrt(x)):
        return len(list)*2-1
    else:
        return len(list)*2
numlist = [0]
for i in range(1,N+1):
    numlist.append(i*getdiv(i))
print(sum(numlist))

Submission status: Runtime Error

Solution code:
C:\Users\ia\Documents\Python Scripts\test.pydef getmax(x,y):
    if x>y:
        return x
    else:
        return y
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[i]にはAの本をi冊読んだ時の時間がそれぞれ保存されている．
    a.append(a[i]+A[i])  #計算量を減らすため，a[i]（1冊前までにかかる時間）を用いる
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]:    #Bの本を読んだ場合の処理はここで実行される．
        j -=1
    ans = max(ans, i+j)
print(ans)

Submission status: Runtime Error

Solution code:
def getmax(x,y):
    if x>y:
        return x
    else:
        return y
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[i]にはAの本をi冊読んだ時の時間がそれぞれ保存されている．
    a.append(a[i]+A[i])  #計算量を減らすため，a[i]（1冊前までにかかる時間）を用いる
for i in range(M):
    b.append(b[i]+B[i])

ans,j = 0,M
for i in range(N+1):
    if a[j]>K:
        break
    while b[j] > K-a[i]:    #Bの本を読んだ場合の処理はここで実行される．
        j -=1
    ans = max(ans, i+j)
print(ans)

Submission status: Runtime Error

Solution code:
def getmax(x,y):
    if x>y:
        return x
    else:
        return y
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[i]にはAの本をi冊読んだ時の時間がそれぞれ保存されている．
    a.append(a[i]+A[i])  #計算量を減らすため，a[i]（1冊前までにかかる時間）を用いる
for i in range(M):
    b.append(b[i]+B[i])

ans,j = 0,K
for i in range(N+1):
    if a[j]>K:
        break
    while b[j] > K-a[i]:    #Bの本を読んだ場合の処理はここで実行される．
        j -=1
    ans = max(ans, i+j)
print(ans)

Submission status: Runtime Error

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

# Aの累積和を保存しておく
# 各Aの要素について、Bが何冊読めるか二分探索する。
# 計算量: AlogB

for i in range(1,len(A)):
  A[i] += A[i-1]
  B[i] += B[i-1]

ans = 0
for i in range(len(A)):
  rest_time = k - A[i]
  if rest_time < 0:
    break
  numb = bisect_left(B, rest_time)
  anstmp = i + 1 + numb 
  ans = max(ans, anstmp)
print(ans)

Submission status: Runtime Error

Solution code:
import sys
from collections import deque
imput = sys.stdin.readline

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

for i in range(n):
    time = k - aa[i]
    cnt = i
    for j in range(m):
        if bb[j] <= time < bb[j+1]:
            cnt += j
            break
    if ans < cnt:
        ans = cnt
        
print(ans)

Submission status: Runtime Error

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

A = [0] + list(map(int, input().split()))
B = [0] + list(map(int, input().split()))

# dp[i][j] = Aをi冊、Bをj冊読んだ時のcost、costがkを超えない範囲で i + jの最大値を求める
# dp[0][0] = 0

# dp = [[0] * (M+1) for _ in range(N+1)]

# どうやって増やしていけばいいんだ ??
# recursionかな
ans = 0
def recur(i, j, cost):
    global ans
    if cost > K:
        return
    ans = max(ans, i + j)
    # dp[i][j] = cost

    if i + 1 < len(A):
        recur(i+1, j, cost+A[i+1])
    if j + 1 < len(B):
        recur(i, j+1, cost+B[j+1])
    return

recur(0, 0, 0)
print(ans)

Submission status: Runtime Error

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

A = [0] + list(map(int, input().split()))
B = [0] + list(map(int, input().split()))

# dp[i][j] = Aをi冊、Bをj冊読んだ時のcost、costがkを超えない範囲で i + jの最大値を求める
# dp[0][0] = 0

dp = [[0] * (M+1) for _ in range(N+1)]

# どうやって増やしていけばいいんだ ??
# recursionかな
ans = 0
def recur(i, j, cost):
    global ans
    if cost > K:
        return
    ans = max(ans, i + j)
    dp[i][j] = cost

    if i + 1 < len(A):
        recur(i+1, j, dp[i][j]+A[i+1])
    if j + 1 < len(B):
        recur(i, j+1, dp[i][j]+B[j+1])
    return

recur(0, 0, 0)
print(ans)

Submission status: Runtime Error

Solution code:
N, M, K = map(int, input().split())
A = list(map(int, input().split())) + [10 ** 10]
B = list(map(int, input().split())) + [10 ** 10]

check = 0
i = 0
while (K >= (check + A[i])) & (i < N):
    check += A[i]
    i += 1

cnt = i

for ii in range(i):
    check2 = sum(A[:(i - ii)])
    j = 0
    while (K >= check2 + B[j]) & (j < M):
        check2 += B[j]
        cnt_j = j
        j += 1
    cnt = max(cnt, i - ii + cnt_j + 1)

print(cnt)

Submission status: Runtime Error

Solution code:
#C
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
asum=[0]
bsum=[0]
for i in range(n):
    asum.append(asum[-1]+a[i])
for i in range(m):
    bsum.append(bsum[-1+b[i]])
ans=0
for i in range(n+1):
    if asum[i]>0:
        break
    while asum[i]+bsum[m]>0 and m>0:
        m-=1
    ans=(ans,i+m)
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()))

s = [[0, 0]] * (k+1)

a, b = [0], [0]

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

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

Submission status: Runtime Error

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

s = [[0, 0]] * (k+1)

aa = 0
bb = 0

for i in range(1, k+1):
    if s[i-1][0] < n and s[i-1][1] < m:
        na = a[s[i-1][0]]
        nb = b[s[i-1][1]]
        ab = aa + bb
        if na > k - ab and nb > k - ab:
            s[k][0] = s[i-1][0]
            s[k][1] = s[i-1][1]
            break
        if i - ab == na:
            s[i][0] = s[i-1][0] + 1
            s[i][1] = s[i-1][1]
            aa += na
        elif i - ab == nb:
            s[i][0] = s[i-1][0]
            s[i][1] = s[i-1][1] + 1
            bb += nb
        else:
            s[i][0] = s[i-1][0]
            s[i][1] = s[i-1][1]
            
    elif s[i-1][0] < n:
        na = a[s[i-1][0]]
        ab = aa + bb
        if na > k - ab:
            s[k][0] = s[i-1][0]
            s[k][1] = s[i-1][1]
            break
        if i - ab == na:
            s[i][0] = s[i-1][0] + 1
            s[i][1] = s[i-1][1]
            aa += na
        else:
            s[i][0] = s[i-1][0]
            s[i][1] = s[i-1][1]
            
    elif s[i-1][1] < m:
        nb = b[s[i-1][1]]
        ab = aa + bb
        if nb > k - ab:
            s[k][0] = s[i-1][0]
            s[k][1] = s[i-1][1]
            break
        if i - ab == nb:
            s[i][0] = s[i-1][0]
            s[i][1] = s[i-1][1] + 1
            bb += nb
        else:
            s[i][0] = s[i-1][0]
            s[i][1] = s[i-1][1]
            
    else:
        s[k][0] = s[i-1][0]
        s[k][1] = s[i-1][1]
        break
        
print(s[k][0] + s[k][1])

Submission status: Runtime Error

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

s = [[0, 0]] * (k+1)

aa = 0
bb = 0

for i in range(1, k+1):
    if s[i-1][0] < n and s[i-1][1] < m:
        na = a[s[i-1][0]]
        nb = b[s[i-1][1]]
        ab = aa + bb
        if i - ab == na:
            s[i][0] = s[i-1][0] + 1
            s[i][1] = s[i-1][1]
            aa += na
        elif i - ab == nb:
            s[i][0] = s[i-1][0]
            s[i][1] = s[i-1][1] + 1
            bb += nb
        else:
            s[i][0] = s[i-1][0]
            s[i][1] = s[i-1][1]
            
    elif s[i-1][0] < n and s[i-1][1] == m:
        na = a[s[i-1][0]]
        ab = aa + bb
        if i - ab == na:
            s[i][0] = s[i-1][0] + 1
            s[i][1] = s[i-1][1]
            aa += na
        else:
            s[i][0] = s[i-1][0]
            s[i][1] = s[i-1][1]
            
    elif s[i-1][0] == n and s[i-1][1] < m:
        nb = b[s[i-1][1]]
        ab = aa + bb
        if i - ab == nb:
            s[i][0] = s[i-1][0]
            s[i][1] = s[i-1][1] + 1
            bb += nb
        else:
            s[i][0] = s[i-1][0]
            s[i][1] = s[i-1][1]
            
    else:
        s[k][0] = s[i-1][0]
        s[k][1] = s[i-1][1]
        break
        
print(s[k][0] + s[k][1])

Submission status: Runtime Error

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

s = [[0, 0]] * (k+1)

aa = 0
bb = 0

for i in range(1, k+1):
    if s[i-1][0] < n and s[i-1][1] < m:
        na = a[s[i-1][0]]
        nb = b[s[i-1][1]]
        ab = aa + bb
        if i - ab == na:
            s[i][0] = s[i-1][0] + 1
            s[i][1] = s[i-1][1]
            aa += na
        elif i - ab == nb:
            s[i][0] = s[i-1][0]
            s[i][1] = s[i-1][1] + 1
            bb += nb
        else:
            s[i][0] = s[i-1][0]
            s[i][1] = s[i-1][1]
            
    elif s[i-1][0] < n:
        na = a[s[i-1][0]]
        ab = aa + bb
        if i - ab == na:
            s[i][0] = s[i-1][0] + 1
            s[i][1] = s[i-1][1]
            aa += na
        else:
            s[i][0] = s[i-1][0]
            s[i][1] = s[i-1][1]
            
    elif s[i-1][1] < m:
        nb = b[s[i-1][1]]
        ab = aa + bb
        if i - ab == nb:
            s[i][0] = s[i-1][0]
            s[i][1] = s[i-1][1] + 1
            bb += nb
        else:
            s[i][0] = s[i-1][0]
            s[i][1] = s[i-1][1]
            
    else:
        s[k][0] = s[i-1][0]
        s[k][1] = s[i-1][1]
        break
        
print(s[k][0] + s[k][1])

Submission status: Runtime Error

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

s = [[0, 0]] * (k+1)

aa = 0
bb = 0

for i in range(1, k+1):
    if s[i-1][0] < n and s[i-1][1] < m:
        na = a[s[i-1][0]]
        nb = b[s[i-1][1]]
        ab = aa + bb
        if i - ab == na:
            s[i][0] = s[i-1][0] + 1
            s[i][1] = s[i-1][1]
            aa += na
        elif i - ab == nb:
            s[i][0] = s[i-1][0]
            s[i][1] = s[i-1][1] + 1
            bb += nb
        else:
            s[i][0] = s[i-1][0]
            s[i][1] = s[i-1][1]
            
    elif s[i-1][0] < n:
        na = a[s[i-1][0]]
        ab = aa + bb
        if i - ab == na:
            s[i][0] = s[i-1][0] + 1
            s[i][1] = s[i-1][1]
            aa += na
        else:
            s[i][0] = s[i-1][0]
            s[i][1] = s[i-1][1]
            
    elif s[i-1][1] < m:
        nb = b[s[i-1][1]]
        ab = aa + bb
        if i - ab == nb:
            s[i][0] = s[i-1][0]
            s[i][1] = s[i-1][1] + 1
            bb += nb
        else:
            s[i][0] = s[i-1][0]
            s[i][1] = s[i-1][1]
            
    else:
        s[i][0] = s[i-1][0]
        s[i][1] = s[i-1][1]
        
print(s[k][0] + s[k][1])

Submission status: Runtime Error

Solution code:
def get(a: list, b: list, pointer1: int, pointer2: int, k: int):
    # print(pointer1, len(a), pointer2, len(b))
    if pointer1 >= len(a) or pointer2 >= len(b) or a[pointer1] + b[pointer2] > k:
           return 0
    return max(pointer1 + pointer2, get(a, b, pointer1 + 1, pointer2, k), get(a, b, pointer1, pointer2 + 1, k))

def main():
    line1 = input()
    line2 = input()
    line3 = input()
    n, m, k = list(map(int, line1.split()))
    a = [0] + list(map(int, line2.split()))
    b = [0] + list(map(int, line3.split()))
    mark1, mark2 = 0, 0
    for i in range(1, len(a)):
        a[i] += a[i-1]
        if a[i] > k:
            mark1 = i
            break
    for i in range(1, len(b)):
        b[i] += b[i-1]
        if b[i] > k:
            mark2 = i
            break
    if mark1:
        a = a[:mark1]
    if mark2:
        b = b[:mark2]
    book = get(a, b, 0, 0, k)
    print(book)
    return

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import numpy as np
import bisect
N,M,K= map(int, input().split())
A=list(map(int, input().split()))
B=list(map(int, input().split()))
if A[0]>K and B[0]>K:print(0);exit()

Asum=[0]
for i in range(N):
  if Asum[-1]+A[i]<=K:
    Asum.append(Asum[-1]+A[i])  

Bsum=[0]
for j in range(M):
  if Bsum[-1]+B[j]<=K:
    Bsum.append(Bsum[-1]+B[j])
AAsum=[]
for i in range(N):
  AAsum.append(K-Asum[i])

#print(Asum)
#print(AAsum)
#print(Bsum)

C=[]
for i in range(len(Asum)):
  C.append(bisect.bisect(Bsum,K-Asum[i])+i-1)

#print(Asum)
#print(AAsum)
#print(Bsum)
#print(C)
print(max(C))

Submission status: Runtime Error

Solution code:
import numpy as np
import bisect
N,M,K= map(int, input().split())
A=list(map(int, input().split()))
B=list(map(int, input().split()))
if A[0]>K and B[0]>K:print(0);exit()

Asum=[0]
for i in range(N):
  if Asum[-1]+A[i]<=K:
    Asum.append(Asum[-1]+A[i])  

Bsum=[0]
for j in range(M):
  if Bsum[-1]+B[j]<=K:
    Bsum.append(Bsum[-1]+B[j])
AAsum=[]
for i in range(N):
  AAsum.append(K-Asum[i])

print(Asum)
print(AAsum)
print(Bsum)
exit()
C=[]
for i in range(len(Asum)):
  C.append(bisect.bisect(Bsum,K-Asum[i])+i-1)

#print(Asum)
#print(AAsum)
#print(Bsum)
#print(C)
print(max(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()))
c=[]
ac = 0
bc = 0
ans = 0
t = 0
while t<k:
  if bc<=m-1 and ac <=n-1:
    if a[ac] > b[bc]:
      t += b[bc]
      bc +=1
      c.
    else:
      t+= a[ac]
      ac+=1
  elif ac >= n and bc<=m-1:
    t += b[bc]
    bc +=1
    print(t)
  elif bc == m and ac<=n-1:
    t+= a[ac]
    ac+=1
  ans+=1

if t>k:
  ans -=1
  
print(ans)

Submission status: Runtime Error

Solution code:
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
import numpy as np
def main():
    n, m, k = map(int, input().split())
    a = np.array(readline().split(), np.int64)
    b = np.array(readline().split(), np.int64)
    aa = a.cumsum()
    ba = b.cumsum()
    aa = aa[aa <= k]
    ba = ba[ba <= k]
    r = np.searchsorted(ba, k, side='right')
    rs = np.searchsorted(ba, k - aa, side='right')
    rs += np.arange(1, len(aa)+1)
    r = max(r, rs.max())
    print(r)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
import numpy as np
def main():
    n, m, k = map(int, input().split())
    a = np.array(readline().split(), np.int64)
    b = np.array(readline().split(), np.int64)
    aa = a.cumsum()
    ba = b.cumsum()
    aa = aa[aa <= k]
    ba = ba[ba <= k]
    r = np.searchsorted(ba, k, side='right')
    rs = np.searchsorted(ba, k - aa, side='right')
    rs += np.arange(1, len(ba))
    r = max(r, rs.max())
    print(r)

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()))
cnt = 0

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

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

A.append(1e10)
B.append(1e10)

time = 0
count_a = 0
count_b = 0

out = []
tmp = []

if A[count_a] < B[count_b]:
  tmp.append(A[count_a])
  count_a += 1
  flag = 0# A
else:
  tmp.append(B[count_b])
  count_b += 1
  flag = 1# B

while(True):
    if flag == 0:
        if sum(tmp) > B[count_b]:
            out.append(B[count_b])
            count_a -= len(tmp)
            count_b += 1
        else:
            tmp.append(A[count_a])
            count_a += 1
    else:
        if sum(tmp) > A[count_a]:
            out.append(A[count_a])
            count_b -= len(tmp)
            count_a += 1
        else:
            tmp.append(B[count_b])
            count_a += 1
    
    if sum(out) + sum(tmp) > K:
        out += tmp[:-1]
        break

print(len(out))

Submission status: Runtime Error

Solution code:
import numpy as np

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

time = 0
count_a = 0
count_b = 0

out = []
tmp = []

if A[count_a] < B[count_b]:
  tmp.append(A[count_a])
  count_a += 1
  flag = 0# A
else:
  tmp.append(B[count_b])
  count_b += 1
  flag = 1# B

while(True):
    if flag == 0:
        if sum(tmp) > B[count_b]:
            out.append(B[count_b])
            count_a -= len(tmp)
            count_b += 1
        else:
            tmp.append(A[count_a])
            count_a += 1
    else:
        if sum(tmp) > A[count_a]:
            out.append(A[count_a])
            count_b -= len(tmp)
            count_a += 1
        else:
            tmp.append(B[count_b])
            count_a += 1
    
    if sum(out) + sum(tmp) > K:
        out += tmp[:-1]
        break

print(len(out))

Submission status: Runtime Error

Solution code:
if __name__ == '__main__':
    N, M, K = map(int, input().split()) 
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    
    acc_A = []
    acc_B = []
    acc_A.append(0)
    acc_B.append(0)
    
    sum_a = 0
    sum_b = 0

    for a in A:
        sum_a += a
        acc_A.append(sum_a)

    for b in B:
        sum_b += b
        acc_B.append(sum_b)

    large_ar = []
    small_ar = []

    if N > M:
        large_ar = acc_A
        small_ar = acc_B
    else:
        large_ar = acc_B
        small_ar = acc_A
    
    ans = 0
    for i in range(len(large_ar)):
        for j in range(ans - i, len(small_ar)):
            if large_ar[i] + small_ar[j] <= K:
                ans = max(ans, i+j)
            else: break
    print(ans)

Submission status: Runtime Error

Solution code:
if __name__ == '__main__':
    N, M, K = map(int, input().split()) 
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    
    acc_A = []
    acc_B = []
    acc_A.append(0)
    acc_B.append(0)
    
    sum_a = 0
    sum_b = 0

    for a in A:
        sum_a += a
        acc_A.append(sum_a)

    for b in B:
        sum_b += b
        acc_B.append(sum_b)

    large_ar = []
    small_ar = []

    if N > M:
        large_ar = acc_A
        small_ar = acc_B
    else:
        large_ar = acc_B
        small_ar = acc_A
    
    ans = 0
    for i in range(len(large_ar)):
        for j in range(ans - i, len(small_ar)):
            if large_ar[i] + small_ar[j] <= K:
                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()))

Asum=[0]
Bsum=[0]

for i in range(N):
    Asum.append(Asum[-1]+A[i])
        
for i in range(M):
    Bsum.append(Bsum[-1]+B[i])
    
m=0
j=M

for i in range(len(Asum)):
    if Asum[i]>K:
        break
    elif Asum[i]+Bsum[j]<=K and m<i+j:
        m=i+j
    elif:
        j-=1
print(m)

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]

for i in range(N):
    Asum.append(Asum[-1]+A[i])
    if Asum[i]>K:
        break
        
for i in range(M):
    Bsum.append(Bsum[-1]+B[i])
    if Bsum[i]>K:
        break
    
m=0
for i in range(len(Asum)):
    for j in range(len(Bsum)):

    elif Asum[i]+Bsum[j]<=K and m<i+j:
        m=i+j
print(m)

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]

for i in range(N):
    Asum.append(Asum[-1]+A[i])
    if Asum[i]>K:
        break
        
for i in range(M):
    Bsum.append(Bsum[-1]+B[i])
    if Bsum[i]>K:
        break
    
m=0
for i in range(len(Asum)):
    for j in range(len(Bsum)):

        elif Asum[i]+Bsum[j]<=K and m<i+j:
            m=i+j
print(m)

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 = K / 60
A = A / 60
B = B / 60

i, j, S = 0, 0, 0
while (S <= K):
    S  += min(A[i], B[j])
    if (A[i] >= B[j]):
        i += 1
    else:
        j += 1
if ((i == 1 & j == 0) | (i == 0 & j == 1)):
    print(0)
else:
    print(i+j)

Submission status: Runtime Error

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

i, j, S = 0, 0, 0
while (S <= K):
    S  += min(A[i], B[j])
    if (A[i] >= B[j]):
        i += 1
    else:
        j += 1
if ((i == 1 & j == 0) | (i == 0 & j == 1)):
    print(0)
else:
    print(i+j)

Submission status: Runtime Error

Solution code:
from functools import lru_cache

ri = lambda S: [int(v) for v in S.split()]


def rii():
    return ri(input())


N, M, K = rii()
A = rii()
B = rii()

i = j = 0


@lru_cache(None)
def dp(i, j, k):
    ki = kj = mki = mkj = 0

    if i < N:
        Ki = k - A[i] if A[i] <= k else 0
        mki = 1 + dp(i + 1, j, Ki) if Ki >= 0 else 0
    if j < M:
        kj = k - B[j] if B[j] <= k else 0
        mkj = 1 + dp(i, j + 1, kj) if kj >= 0 else 0

    return max(mki, mkj)


print(dp(0, 0, K))
#print(dp.cache_info())

Submission status: Runtime Error

Solution code:
ri = lambda S: [int(v) for v in S.split()]


def rii():
    return ri(input())


N, M, K = rii()
A = rii()
B = rii()

i = j = 0


def dp(i, j, k):
    ki = kj = mki = mkj = 0

    if i < N:
        Ki = k - A[i] if A[i] <= k else 0
        mki = 1 + dp(i + 1, j, Ki) if Ki >= 0 else 0
    if j < M:
        kj = k - B[j] if B[j] <= k else 0
        mkj = 1 + dp(i, j + 1, kj) if kj >= 0 else 0

    return max(mki, mkj)


print(dp(0, 0, K))

Submission status: Runtime Error

Solution code:
ri = lambda S: [int(v) for v in S.split()]


def rii():
    return ri(input())


N, M, K = rii()
A = rii()
B = rii()

i = j = 0


def dp(i, j, k):
    print(i, j, k)
    ki = kj = mki = mkj = 0

    if i < N:
        Ki = k - A[i] if A[i] <= k else 0
        mki = 1 + dp(i + 1, j, Ki) if Ki >= 0 else 0
    if j < M:
        kj = k - B[j] if B[j] <= k else 0
        mkj = 1 + dp(i, j + 1, kj) if kj >= 0 else 0

    return max(mki, mkj)


print(dp(0, 0, K))

Submission status: Runtime Error

Solution code:
from collections import deque

def chk(i,time,a,b):
    if len(a)==0 and len(b)==0:
        return i
    if time>k:
        return i-1
    
    if len(a)==0:
        tmp_a = 10**9
    else:
        tmp_a = a.popleft()
        
    if len(b)==0:
        tmp_b = 10**9
    else:
        tmp_b = b.popleft()
        
    if tmp_a>tmp_b:
        time += tmp_b
        a.appendleft(tmp_a)
        i += 1
    else:
        time += tmp_a
        b.appendleft(tmp_b)
        i += 1
        
    tmp = chk(i,time,a,b)
    return tmp

n,m,k = map(int,input().split())
tmp_a = list(map(int,input().split()))
tmp_b = list(map(int,input().split()))
a = deque()
b = deque()
a.extend(tmp_a)
b.extend(tmp_b)
#print(a,b)

print(chk(0,0,a,b))