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:
A,B, K=map(int,input().split())
List_A = list(map(int, input().split()))
List_B = list(map(int, input().split()))
res = 0
inter = 0
n = A+B
for i in range(n):
  if len(List_A)==0:
    inter+=List_B.pop(0)
  elif len(List_B)==0:
    inter+=List_A.pop(0)
  else:
    if List_A[0]>List_B[0]:
      inter+=List_B.pop(0)
    elif List_A[0] < List_B[0]:
      inter+=List_A.pop(0)
    else:
      if List_B[1] > List_A[1]:
        inter+=List_A.pop(0)
      elif List_A[1] > List_B[1]:
        inter+=List_B.pop(0)
      else:
        if len(List_A) > len(List_B):
          inter = inter + List_A.pop(0)
        else:
          inter = inter + List_B.pop(0)
  if K < inter:
    break
  else:
    res +=1
print(res)

Submission status: Runtime Error

Solution code:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
for i in range(1,n):
    a[i]+=a[i-1]
    if a[i]>k:
        n=i
        break
for i in range(1,m):
    b[i]+=b[i-1]
    if b[i]>k:
        m=i
        break

ans, j = 0, m
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:
nmk = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
n = nmk[0]
m = nmk[1]
k = nmk[2]

def dp(a, b, k):
  ak = 0
  bk = 0
  #print(a, b, k)
  if (len(a)==0 and len(b)==0) or k<=0:
    return 0;
  if (len(a)>0 and a[0]<=k):
    ak = dp(a[1:], b, k-a[0]) + 1
  if (len(b)>0 and b[0]<=k):
    bk = dp(a, b[1:], k-b[0]) + 1
  return max([ak, bk])

ans = dp(a, b, k)
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_sum = []
a_sum = 0
for a in A:
    a_sum += a
    A_sum.append(a_sum)

B_sum = []
b_sum = 0
for b in B:
    b_sum += b
    B_sum.append(b_sum)

max_count = 0
for idx, a_sum in enumerate(A_sum):
    j = M - 1
    if a_sum > K:
        break

    while B_sum[j] + a_sum > K:
        j -= 1
    max_count = max(max_count, idx+1 + j+1)
print(max_count)

Submission status: Runtime Error

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

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

if A[0] > K:
    if B[M-1] <= K:
        print(M)
    else:
        i = 0
        while B[i] <= K:
            i += 1
        print(i)
elif B[0] > K:
    if A[N-1] <= K:
        print(N)
    else:
        i = 0
        while A[i] <= K:
            i += 1
        print(i)
else:
    ans, i = Bind, 0
    for j in range(Bind, -1, -1):
        while Asum[i] + Bsum[j] <= K:
            i += 1
            if i == N:
                if ans < N + j + 1:
                    print(N+j+1)
                else:
                    print(ans)
                exit()
        ans = max(i+j+1, ans)
    print(ans)

Submission status: Runtime Error

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

 
N, M, K = map(int, input().split())
A = [int(n) for n in input().split()]
B = [int(n) for n in input().split()]
 
A = np.array(A)
B = np.array(B)
 
A = np.cumsum(A)
B = np.cumsum(B)
 
A1 = np.zeros((len(A),2))
A1[:,0] = A
A1[:,1] = np.arange(1,len(A)+1)
 
B1 = np.zeros((len(B),2))
B1[:,0] = B
B1[:,1] = np.arange(1,len(B)+1)
 
C1 = np.zeros((len(A)*len(B),2))
lenB = len(B)
for i in range(len(A)):
    for j in range(len(B)):
        C1[lenB*i+j,:] = A1[i,:] + B1[j,:]
C2 = np.array([C[1] for C in C1 if C[0] <= K])
 
if len(C2):
    print(int(C2.max()))
else:
    print(0)

Submission status: Runtime Error

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

def Tundoku(a,b,count,k,K,N,M):
    if k > K :
        count -= 1
        return count
    else:
        if a == N-1 and b == M-1:
            k += min(A[a],B[b])
            if k > K:
                return count
            else:
                k += max(A[a],B[b])
                if k > K:
                    count += 1
                    return count
                else:
                    count = count + 2
                    return count
        if a == N-1 and b != M-1:
            k += B[b]
            count += 1
            return Tundoku(a,b+1,count,k,K,N,M)
        elif a != N-1 and b == M-1:
            k += A[a]
            count += 1
            return Tundoku(a+1,b,count,k,K,N,M)
        else:
            if A[a] == B[b]:
                k += A[a]
                count += 1
                return max(Tundoku(a+1,b,count,k,K,N,M),Tundoku(a,b+1,count,k,K,N,M))

            elif A[a] > B[b] :
                k += B[b]
                count += 1
                return Tundoku(a,b+1,count,k,K,N,M)
            else:
                k += A[a]
                count += 1
                return Tundoku(a+1,b,count,k,K,N,M)

ans = Tundoku(0,0,0,0,K,N,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()))


A.append(K)
B.append(K)

sumA = []
sumB = []

sumAi = 0
for i in range(N+1):
    sumAi += A[i]
    if sumAi > K:
        break
    else:
        sumA.append(sumAi)
AA = A[:i]

sumBj = 0
for j in range(M+1):
    sumBj += B[j]
    if sumBj > K:
        break
    else:
        sumB.append(sumBj)
BB = B[:j]

NN = len(AA)
MM = len(BB)

        
#if NN == 0:
#    ans = MM
#else:
ans = NN+MM
time = sumA[-1]+sumB[-1]
AA_rem = []
BB_rem = []
if time > K:
    for i in range(NN+MM):
        if AA[-1]>BB[-1]:
            nozoku = AA.pop(-1)
            AA_rem.append(nozoku)
            time -= nozoku
            ans -= 1
            last_nozo="A"
        else:
            nozoku = BB.pop(-1)
            BB_rem.append(nozoku)
            time -= nozoku
            ans -= 1
            last_nozo = "B"
        if time <= K:
            break
        
    if last_nozo == "A":
        for j in range(len(BB)):
            modosu = BB.pop(0)
            if time + modosu <= K:
                time += modosu
                ans += 1
            else:
                break
    else:
        for i in range(len(AA)):
            modosu = AA.pop(0)
            if time + modosu <= K:
                time += modosu
                ans += 1
            else:
                break

print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
import sys
sys.setrecursionlimit(10**7)

 
N, M, K = map(int, input().split())
A = [int(n) for n in input().split()]
B = [int(n) for n in input().split()]
 
A = np.array(A)
B = np.array(B)
 
A = np.cumsum(A)
B = np.cumsum(B)
 
A1 = np.zeros((len(A),2))
A1[:,0] = A
A1[:,1] = np.arange(1,len(A)+1)
 
B1 = np.zeros((len(B),2))
B1[:,0] = B
B1[:,1] = np.arange(1,len(B)+1)
 
C1 = np.zeros((len(A)*len(B),2))
lenB = len(B)
for i in range(len(A)):
    for j in range(len(B)):
        C1[lenB*i+j,:] = A1[i,:] + B1[j,:]
C2 = np.array([C[1] for C in C1 if C[0] <= K])
 
if len(C2):
    print(int(C2.max()))
else:
    print(0)

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

asum = list(accumulate(a))
bsum = list(accumulate(b))

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

Submission status: Runtime Error

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

def ii(): return int(input())
def fi(): return float(input())
def si(): return input()
def lii(): return list(map(int, input().split()))
def lfi(): return list(map(float, input().split()))
def vvi(a,b,d): return [[d] * a for i in range(b)]

inf = 10**18
mod = 10**9+7

n = ii()
ans = 0
for i in range(n):
    a = i+1
    t = n//a
    ans += a*t*(t+1)//2

print(ans)

Submission status: Runtime Error

Solution code:
from itertools import accumulate

N, M, K = map(int, input().split())
*A, = map(int, input().split())
*B, = map(int, input().split())
cumsum_A, cumsum_B = [0] + list(accumulate(A)), [0] + list(accumulate(B))
ans = 0
j = M
for i in range(N+1):
    if cumsum_A[i] > K: break
    while cumsum_A[i] + cumsum_B[j] >= K: j -= 1
    ans = max(ans, i + j)
print(ans)

Submission status: Runtime Error

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

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:
alen,blen,k = map(int,input().split())
alist = list(map(int,input().split()))
blist = list(map(int,input().split()))
max = 0

bcount = blen
while sum(blist[:bcount]) > k:
    bcount -= 1
if bcount != 0:
    bsum = sum(blist[:bcount])
for a in range(alen+1):
    acount = alen-a
    asum = sum(alist[:acount])
    if bcount != 0:
        while asum + bsum > k:
            bcount -= 1
            bsum -= blist[bcount-1]
    if acount + bcount > max and asum + sum(blist[:bcount])<=k:
        max = acount + bcount

print(max)

Submission status: Runtime Error

Solution code:
from collections import deque
n,m,k = map(int,input().split())
A = deque(map(int,input().split()))
B = deque(map(int,input().split()))

i = 0
time = 0
count = 0

while(time < k):
  if(len(A) == 0) & (len(B) == 0):
    break
    
  if(len(A) == 0):
    time += B[i]
    count += 1
    B.popleft()
  
  elif(len(B) == 0):
    time += A[i]
    count += 1
    A.popleft()
  
  elif((len(A) != 0) & (len(B) != 0)):
    if(A[i] >= B[i]):
      time += A[i]
      count += 1
      A.popleft()
    if(A[i] < B[i]):
      time += B[i]
      count += 1
      B.popleft()

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 = [0]
sb = [0]
for i in range(n):
    sa.append(sa[i]+a[i])
for i in range(m):
    sb.append(sb[i]+b[i])
    
#片方全部見ていくともう片方が簡単に求まる
ans = 0
for i in range(n+1):
    if a[i] > k:
        break
    while b[m] > k - a[i]:
        m -= 1
    ans = max(ans,i+m)
print(ans)

Submission status: Runtime Error

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

for i in range(1, min(N,M)):
  As[i] = As[i] + As[i-1]
  Bs[i] = Bs[i] + Bs[i-1]

if N > M:
  for i in range(M,N):
    As[i] = As[i] + As[i-1]
elif M>N:
  for i in range(N, M):
    Bs[i] = Bs[i] + Bs[i-1]

ans,j=0,M
for i in range(N + 1): 
  if As[i]>K:
    break
  while Bs[j] > K - As[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()))

def dfs(ai, bi, t, c):
    if t > k:
        return c - 1
    elif ai == n and bi == m:
        return c
    elif ai == n:
        return dfs(ai, bi + 1, t + b[bi], c + 1)
    elif bi == m:
        return dfs(ai + 1, bi, t + a[ai], c + 1)
    return max(dfs(ai + 1, bi, t + a[ai], c + 1), dfs(ai, bi + 1, t + b[bi], c + 1))

ans = dfs(0, 0, 0, 0)

print(ans)

Submission status: Runtime Error

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

for i in range(len(A)):
    count += A[i]
    if count > K:
        del A[i-1:]
        count=0
        ANS += len(A)
        break

for i in range(len(B)):
    count += B[i]
    if count > K:
        del B[i-1:]
        count=0
        ANS += len(B)
        break

count = sum(A) + sum(B)




while count > K:
    if A[-1] > B[-1]:
        count -= A[-1]
        del A[-1]
        ANS -= 1
    else:
        count -= B[-1]
        del B[-1]
        ANS -= 1

print(ANS)

Submission status: Runtime Error

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

cnt = 0
time = 0
A_s = sum(A)
B_s = sum(B)

if A_s + B_s <= k:
  print(len(A)+len(B))
  
elif A[-1] > k and B[-1] > k:
  print(0)
  
else:
  while time <= k:
      if A[-1] >= B[-1]:
          time += B[-1]
          B.pop()
          cnt += 1
          print(B)
          if len(B) == 0:
              B.append(10000000000)
      else:
         time += A[-1]
         A.pop()
         cnt += 1
         print(A)
         if len(A) == 0:
             A.append(10000000000)
  print(cnt-1)

Submission status: Runtime Error

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

la, lb = [0], [0]
for i in range(n):
  la.append(la[i] + a[i])
for i in range(m):
  lb.append(lb[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:
a,b,c=map(int,input().split())
li_a=list(map(int,input().split()))
li_b=list(map(int,input().split()))

count=0
x=0
y=0
while c>=0:
  if a!=0 and b!=0:
    c=c-min(li_a[x],li_b[y])
    if li_b[y]>=li_a[x]:
      x+=1
      a-=1
    else:
      y+=1
      b-=1
    if c<0:
      break
    else:
      count+=1
  if a!=0 and b==0:
    c=c-li_a[x]
    x+=1
    a-=1
    if c<0:
      break
    count+=1
  if a==0 and b!=0:
    y+=1
    b-=1
    c=c-li_b[y]
    if c<0:
      break
    count+=1
  if a==0 and b==0:
    break
    
    
print(count)

Submission status: Runtime Error

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

S_A = [0] * (N + 1)
S_B = [0] * (N + 1)
for i in range(N):
  S_A[i+1] = S_A[i] + A[i]

for i in range(M):
  S_B[i+1] = S_B[i] + B[i]
  
ans = 0
a = 0
for i in range(M, -1, -1):
  s = S_B[i]
  while a<N:
    if s + S_A[a + 1]<=K:
      a += 1
    else:
      break
  ans = max(ans, i + a)
print(ans)

Submission status: Runtime Error

Solution code:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ans=0
aindex=n+1
bindex=m+1
acumsum = [0]
bcumsum = [0]

ab =0
for aa in range(n):
  ab += a[aa]
  acumsum.append(ab)# = ab
  if ab>k:
    aindex= aa
    break

ab =0
for bb in range(m):
  ab += b[bb]
  bcumsum.append(ab)
  if ab>k:
    bindex= bb
    break

j= m
for i in range(n+1):
  if acumsum[i] >k:
    break
  while bcumsum[j] > k-acumsum[i]:
    j -=1
  ans = max(ans, i+j)

print(ans)

Submission status: Runtime Error

Solution code:
import random
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ans=random.randint(0,n+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()))
ans = 0
ai = 0
tmp = 0

for i in range(n):
    if tmp + a[i] <= k:
        tmp = tmp + a[i]
        ans += 1
        ai = i

for i in range(m):
    if tmp + b[i] <= k:
        tmp = tmp + b[i]
        ans += 1
    elif tmp - a[ai] + b[i] <= k:
        tmp = tmp - a[ai] + b[i]
        ai -= 1

print(ans)

Submission status: Runtime Error

Solution code:
import sys
import  math
import fractions
from collections import defaultdict
stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

N,M,K=nm()
INF=10**18
A=nl()
B=nl()
A.append(INF)
B.append(INF)
A_c=0
B_c=0
ans=0
sum_l_A=[INF]*(N+2)
sum_l_B=[INF]*(M+2)

sum_l_A[0]=0
sum_l_B[0]=0
for i in range(1,N+2):
    sum_l_A[i]=sum_l_A[i-1]+A[i-1]

for i in range(1,M+2):
    sum_l_B[i]=sum_l_B[i-1]+B[i-1]



ans=0
a_c=0
b_c=0
now_resume=0
for j in range(N+M+4):
    resume=0
    a_c+=1
    while(1):
        now_resume=sum_l_A[a_c]+sum_l_B[b_c]
        if(now_resume>sum_l_A[a_c+1]+sum_l_B[b_c+1]):
            a_c-=1
            b_c+=1
        else:
            break
    resume=sum_l_A[a_c]+sum_l_B[b_c]
    if(K<resume):
        print(ans)
        sys.exit(0)
    ans+=1
    now_resume=resume

Submission status: Runtime Error

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

time_A = list(map(int, input().split()))
time_B = list(map(int, input().split()))
max_books = 0
num_books = 0
allot_to_A = 0
allot_to_B = K
time_bankB = allot_to_B
read_in_B = []
baf_timeB = 0

for i in range(len(time_B)):
    if time_B[i] <= time_bankB:
        time_bankB -= time_B[i]
        num_books += 1
        read_in_B.append(time_B[i])
    else:
        baf_timeB = time_bankB
if baf_timeB == 0:
    baf_timeB = K - sum(time_B)

max_books = num_books
tmp = max_books


for i in range(len(time_A)):
    tmp = max_books
    dif = 1
    allot_to_A += time_A[i]
    allot_to_B -= time_A[i]
    if allot_to_B < 0:
        break
    time_to_reduce = time_A[i]
    while time_to_reduce > 0:
        if time_to_reduce <= baf_timeB:
            baf_timeB -= time_to_reduce
            break
        else:
            baf_timeB += read_in_B[-1]
            dif -= 1
            del read_in_B[-1]
    tmp += dif
    max_books = max(tmp, max_books)

print(max_books)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Jun 27 21:07:13 2020

@author: naoki
"""
from collections import deque 

N,M,K = map(int,input().split())
A = deque(map(int,input().split()))
B = deque(map(int,input().split()))
time = 0 
count = 0 

while time <= K:
    count += 1
    if  len(A) >=1 and len(B)>=1:
        if A[0] < B[0]:
            time += A[0]
            A.popleft()
        else:
            time += B[0]
            B.popleft()
    elif len(A) == 0:
        time += B[0]
        B.popleft()
    else:
        time += A[0]
        A.popleft()
if count >= 2:    
    print(count-1)
else:
    print(0)

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(a[i] + A[i])

ans, j = o, 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 itertools
import numpy as np 
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
acc = list(itertools.accumulate(a))
bcc = list(itertools.accumulate(b))

acc = np.array(acc)
#print(acc)
bcc = np.array(bcc)

checkA = np.where(acc <= k)
chA = checkA[0]
checkB = np.where(bcc <= k)
chB = checkB[0]

if (len(chA) > len(chB)):
  a1 = chA
  b1 = chB
else:
  a1 = chB
  b1 = chA

if (len(a1) == 0):
  print(0)
  exit()

ans = 0

for i in range(len(a1) -1, -1, -1):
  #print(i, acc[a1[i]])
  rest = k - acc[a1[i]]
  tar = np.where(bcc <= rest)
  if (len(tar[0]) == 0):
    num = 0
  else:
    num = tar[0][-1]

  #print('num', num)
  ans = max(num + i + 2, ans)
    

print(ans)

Submission status: Runtime Error

Solution code:
n, M, k = map(int,input().split())
a_l = list(map(int,input().split()))
b_l = list(map(int,input().split()))
read_a = [0]*n
read_b = [0]*M
time = 0
ans = 0
memo = 0
for j in range(n):
    if time + a_l[j] <= k:
        time += a_l[j]
        read_a[j] = 1
        memo = j
        ans = j+1
    else:
        break

kotae = [ans]


def dfs(i,a,t,m):
    global kotae
    if i < M:
        if b_l[i] + t <= k:
            tt = t + b_l[i]
            aa = a + 1
            kotae.append(aa)
            ii = i+1
            mm = m
            #print(aa)
            dfs(ii,aa,tt,mm)
            
        else:
            if m >= 0:
                tt = t - a_l[m]
                mm = m - 1
                aa = a - 1
                ii = i
                dfs(ii,aa,tt,mm)
            


dfs(0,ans,time,memo)


print(max(kotae))

Submission status: Runtime Error

Solution code:
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n=int(input())

def eratosthenes(lim):
  is_p=[2]*lim

  is_p[0]=0
  is_p[1]=1

  for i in range(2,lim):
    for j in range(i*2,lim,i):
      is_p[j] += 1

  return is_p

lim=n+1
is_p=eratosthenes(lim)

ans=0
for i in range(1,n+1):
  ans+=i*is_p[i]
print(ans)

Submission status: Runtime Error

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

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

a_wa = [0]
max_a_idx = None
for idx, a in enumerate(A):
    a_wa.append(a_wa[-1] + a)

    if a_wa[-1] > K:
        break

max_a_idx = len(a_wa)
b_wa = [0]
max_b_idx = None
for idx, b in enumerate(B):
    b_wa.append(b_wa[-1] + b)

    if b_wa[-1] > K:
        break

max_b_idx = len(b_wa)

if max_a_idx + max_b_idx == 2:
    print(0)
    exit()
elif max_a_idx == 1:
    print(max_b_idx)
    exit()
elif max_b_idx == 1:
    print(max_a_idx + 1)
    exit()

out_num = 0
b_idx = M - 1
for a_idx in range(max_a_idx):
    while b_wa[b_idx] > K - a_wa[a_idx]:
        b_idx -= 1
    out_num = max(out_num, a_idx + b_idx)

print(out_num)

Submission status: Runtime Error

Solution code:
import random
n, m, k = map(int, input().split())
# n, m, k = random.randint(1, 10**5), random.randint(1, 10**5), random.randint(10**7, 10**8)
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
# a_list = [random.randint(1, 10**2) for i in range(n)]
# b_list = [random.randint(1, 10**2) for i in range(m)]
# print(n,m,k)
# print(a_list[0], b_list[0])
a_sum = [0]
b_sum = [0]
for i in range(1, max(n+1, m+1)):
    if i < n+1:
        a_sum.append(a_sum[i-1] + a_list[i-1])
    if i < m+1:
        b_sum.append(b_sum[i-1] + b_list[i-1])

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

Submission status: Runtime Error

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

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

cnt = 0

while k >= a[0] or k >= b[0]:
    if a[0] < b[0]:
        k -= a.popleft()
        cnt += 1

    elif a[0] > b[0]:
        k -= b.popleft()
        cnt += 1
    else:
        for i in range(1, min(len(a), len(b))):
            if a[i] < b[i]:
                for t in range(0, i+1):
                    k -= a.popleft()
                    cnt += 1
                    if k < a[0]:
                        break
                break
            elif a[i] > b[i]:
                for t in range(0, i+1):
                    k -= b.popleft()
                    cnt += 1
                    if k < b[0]:
                        break
                break
        else:
            if len(a) > len(b):
                for i in range(len(a)):
                    k -= a.popleft()
                    cnt += 1
                    if k < a[0]:
                        break
            else:
                for i in range(len(b)):
                    k -= b.popleft()
                    cnt += 1
                    if k < b[0]:
                        break
    if a == deque([]):
        for i in range(len(b)):
            if k < b[0]:
                break
            k -= b.popleft()
            cnt += 1
        break
    if b == deque([]):
        for i in range(len(a)):
            if k < a[0]:
                break
            k -= a.popleft()
            cnt += 1
        break
print(cnt)

Submission status: Runtime Error

Solution code:


import sys
import math
import itertools
import collections

def solve(N,M,K,A,B):
    accumA = [0,A.pop(0)]
    accumB = [0,B.pop(0)]
    for a in A:
        accumA.append(accumA[-1] + a)
    for b in B:
        accumB.append(accumB[-1] + b)
    ans = 0
    j = 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)
    return ans

def main():
    N,M,K = map(int,input().split())
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))
    # solve()
    print(solve(N,M,K,A,B))

if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

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

a_wa = [0]
max_a_idx = None
for idx, a in enumerate(A):
    a_wa.append(a_wa[-1] + a)

    if a_wa[-1] > K:
        break

max_a_idx = len(a_wa)
b_wa = [0]
max_b_idx = None
for idx, b in enumerate(B):
    b_wa.append(b_wa[-1] + b)

    if b_wa[-1] > K:
        break

max_b_idx = len(b_wa)

if max_a_idx + max_b_idx == 2:
    print(0)
    exit()
elif max_a_idx == 1:
    print(max_b_idx)
    exit()
elif max_b_idx == 1:
    print(max_a_idx + 1)
    exit()

out_num = 0
b_idx = M-1
for a_idx in range(max_a_idx):
    while b_wa[b_idx] > K - a_wa[a_idx]:
        j -= 1
    out_num = max(out_num, a_idx + b_idx)

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

def dfs(ai, bi, t, c):
    if t > k:
        return c - 1
    elif ai == n - 1 and bi == m - 1:
        return c
    elif ai == n - 1:
        return dfs(ai, bi + 1, t + b[bi], c + 1)
    elif bi == m - 1:
        return dfs(ai + 1, bi, t + a[ai], c + 1)
    return max(dfs(ai + 1, bi, t + a[ai], c + 1), dfs(ai, bi + 1, t + b[bi], c + 1))

ans = dfs(0, 0, 0, 0)

print(ans)

Submission status: Runtime Error

Solution code:
n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a = 0
b = 0
ans = 0
sumA = 0
sumB = 0
for i in range(len(A)):
  sumA =sumA +A[i]
  if sumA <= k:
    a += 1
  else:
    break

for i in range(len(B)):
  sumB =sumB +B[i]
  if sumB <= k:
    b += 1
  else:
    break
#print(a)
#print(b)
ab = a+b
su = sum(A[0:a]) + sum(B[0:b])
if su <= k:
  print(ab)
else:
  for i in range(max(a,b)):
    ans += 1
    if A[a-1] >= B[b-1]:
      if su - A[a-1] <= k:
        break
      else:
        a -=1
    else:
      if su - B[b-1] <= k:
        break
      else:
        b -=1   
  print(ab-ans)

Submission status: Runtime Error

Solution code:
a = input().split()
a = [int(a)for a in a]
lis = []

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

for i in b:
    lis.append(i)

for i in c:
    lis.append(i)

lis.sort()

count = 0
time = a[2]
honn = 0

while time >= lis[count]:
    time = time - lis[count]
    count += 1
    honn += 1

print(honn)

Submission status: Runtime Error

Solution code:
def resolve():
    import numpy as np

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

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

    ans = 0
    j = M
    for i in range(N + 1):
        if A_cumsum[i] > K:
            break
        while A_cumsum[i] + B_cumsum[j] > K:
            j -= 1

        ans = max(ans, i + j)

    print(ans)

resolve()

Submission status: Runtime Error

Solution code:
root = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))    
minute=0
books=0
ai=0
bi=0

while minute <= root[2]:
    if a[ai] < b[bi]:
        minute += a[ai]
        books += 1
        ai += 1
    elif b[bi] < a[ai]:
        minute += b[bi]
        books += 1
        bi += 1
    else:
        if len(a) == ai + 1 and len(b) == bi + 1:
            books += 1
            break
        if len(a) > ai + 1:
            minute += a[ai]
            books += 1
            ai += 1
        elif len(b) > bi + 1:
            minute += b[bi]
            books += 1
            bi += 1

print(books-1)

Submission status: Runtime Error

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

N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
a = [0]+list(accumulate(A))
b = [0]+list(accumulate(B))
ans,j = 0,M
for i in range(N+1):
    if i > K:
        break
    while b[j] > K - a[i]:
        j -= 1
    ans = max(ans,i+j)
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(N):
        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)
    
if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

# 求解処理
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)