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:
i1 = input().split(" ")
n = int(i1[0])
m = int(i1[1])
k = int(i1[2])
i2 = input().split(" ")  # desk A
i3 = input().split(" ")  # desk B

t = 0
at = 0
bt = 0


def isWithinBudget(val, k):
    if k - val < 0:
        return False
    else:
        return True


def findBestProceeding(param, param1):
    if int(param[0]) > int(param1[0]):
        return 1
    elif int(param[0]) < int(param1[0]):
        return 0
    else:
        return findBestProceeding(param[1:],param1[1:])
    


for i in range(len(i2) + len(i3)):
    if bt >= len(i3) and at >= len(i2):
        break
    elif bt >= len(i3):
        # pick form desk A
        val = int(i2[at])
        at += 1
        if isWithinBudget(val, k):
            k -= val
            t += 1
        else:
            break
    elif at >= len(i2):
        val = int(i3[bt])
        bt += 1
        if isWithinBudget(val, k):
            k -= val
            t += 1
        else:
            break
    else:
        if int(i3[bt]) > int(i2[at]):
            # pick form desk A
            val = int(i2[at])
            at += 1
            if isWithinBudget(val, k):
                k -= val
                t += 1
            else:
                break
        elif int(i3[bt]) == int(i2[at]):
            p = findBestProceeding(i2[at:],i3[bt:])
            if p == 0:
                # pick form desk A
                val = int(i2[at])
                at += 1
                if isWithinBudget(val, k):
                    k -= val
                    t += 1
                else:
                    break
            else:
                val = int(i3[bt])
                bt += 1
                if isWithinBudget(val, k):
                    k -= val
                    t += 1
                else:
                    break
        else:
            val = int(i3[bt])
            bt += 1
            if isWithinBudget(val, k):
                k -= val
                t += 1
            else:
                break

    if k == 0:
        break
print(t)

Submission status: Runtime Error

Solution code:
def resolve():
    n, m ,k= map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    a.append(10**9+1)
    b.append(10**9+1)
    ans=[]
    def f(i,j,p,ansk):

        if (a[i] > p and b[j]>p):
            ans.append(ansk)

        if a[i]<=p:
            f(i+1,j,p-a[i],ansk+1)

        if b[j]<=p:
            f(i,j+1,p-b[j],ansk+1)
    f(0,0,k,0)
    print(max(ans))
resolve()

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(len(b)):
  a.append(b[i]):
a.sort()
j=0
d=0
c=0
while(d<=k and j<len(a)):
  d=d+a[j]
  j=j+1
  c=c+1
if(d>k):
  print(c-1)
else:
  print(c)

Submission status: Runtime Error

Solution code:
import math
n = int(input())
def num_div(n) : 
    cnt = 0
    for i in range(1, (int)(math.sqrt(n)) + 1) : 
        if (n % i == 0) : 
            if (n / i == i) : 
                cnt = cnt + 1
            else :
                cnt = cnt + 2 
    return cnt*n 
s = 0
for i in range(1, n+1):
    s+=num_div(i)
print(s)

Submission status: Runtime Error

Solution code:
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
Sum = sum(a) + sum(b)
ans = 0
count = 0
if Sum <= k:
  print(len(a) + len(b))

else:
  while True:
    if (len(a) != 0) & (len(b) != 0) & (a[0] < b[0]):
      ans += a[0]
      a.pop(0)
      count += 1
      if ans > k:
        print(count - 1)
        break
      
    elif (len(a) != 0) & (len(b) != 0) & (b[0] <= a[0]):
      ans += b[0]
      b.pop(0)
      count += 1
      if ans > k:
        print(count - 1)
        break

    elif len(a) == 0:
      ans += b[0]
      b.pop(0)
      count += 1
      if ans > k:
        print(count - 1)
        break

    else:
      ans += a[0]
      a.pop(0)
      count += 1
      if ans > k:
        print(count - 1)
        break

Submission status: Runtime Error

Solution code:
a,b,c = map(int, input().split())
l1 = list(map(int, input().split()))
l2= list(map(int, input().split()))
i,j, s, d=0,0,0,0
while(s<=c and (i<=(a-1) or j<=(b-1))):
    if((i<=(a-1))and l1[i]<l2[j]):
        if s+l1[i]<=c:
            s=s+l1[i]
            i=i+1
            d+=1
        else:
            break
    elif(j<=(b-1)):
        if (s+l2[j]<=c):
            s=s+l2[j]
            j=j+1
            d+=1
        else:
            break
print(d)

Submission status: Runtime Error

Solution code:
import sys

sys.setrecursionlimit( 10 * 18 )

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

a.append( 10 ** 9 + 1 )
b.append( 10 ** 9 + 1 )

def dp( i, j, t ):
    next_i = min( i+1, n )
    next_j = min( j+1, m )
    if i == n and j == m:
        return 0
    elif a[ i ] + t > k and b[ j ] + t > k:
        return 0
    elif a[ i ] + t > k:
        return dp( i, next_j, t+b[j] ) + 1
    elif b[ j ] + t > k:
        return dp( next_i, j, t+a[i] ) + 1
    else:
        return max( dp( next_i, j, t+a[i] ), dp( i, next_j, t+b[j] ) ) + 1

read = dp( 0, 0, 0 )
    
print( read )

Submission status: Runtime Error

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

inta = 0
intb = 0
sum = 0
while(sum<=K):
  if(inta+1<len(A) and intb+1<len(B)):
    if(A[inta]<B[intb]):
      sum = sum + A[inta]
      inta+=1
    else:
      sum = sum + B[intb]
      intb+=1
  elif(inta+1>len(A)):
      sum = sum + B[intb]
      intb+=1
  else:
      sum = sum + A[inta]
      inta+=1

print(inta+intb-1)

Submission status: Runtime Error

Solution code:
A=[]
B=[]
books = 0
time = 0
n, m, k = map(int,input().split())
i = n-1
j = m - 1
A = list(map(int,input().strip().split()))[:n] 
B = list(map(int,input().strip().split()))[:m] 
while not(time > k) :
    if ((i> -1 and j> -1 and A[i]<B[j]) or (i>-1 and not(j>-1))):
        time = time+A[i]
        i=i-1
        books=books+1
    elif ((i> -1 and j> -1 and (not(A[i]<B[j]))) or (j>-1 and not(i>-1))):
            time = time+A[i]
            i=i-1
            books=books+1
print(books)

Submission status: Runtime Error

Solution code:
import sys
import math
import heapq
from collections import defaultdict, deque
sys.setrecursionlimit(100000) 
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'''
def count(i,n,j,m,a,b,k):
    if i==n:
        if j==m:
            return 0
        if b[j]<=k:
            return 1+count(i,n,j+1,m,a,b,k-b[j])
        return 0
    elif j==m:
        if i==n:
            return 0
        if a[i]<=k:
            return 1+count(i+1,n,j,m,a,b,k-a[i])
        return 0
    else:
        if a[i]>k and b[j]>k:
            return 0
        if a[i]>k:
            return 1+count(i,n,j+1,m,a,b,k-b[j])
        if b[j]>k:
            return 1+count(i+1,n,j,m,a,b,k-a[i])
        return max(1+count(i,n,j+1,m,a,b,k-b[j]),1+count(i+1,n,j,m,a,b,k-a[i]))

n,m,k=rm()
a=rl()
b=rl()
i=0;j=0;
print(count(i,n,j,m,a,b,k))

Submission status: Runtime Error

Solution code:
# C - Tsundoku
import sys
sys.setrecursionlimit = 10**7

N, M, K = map(int, input().split())
A = list(int(a) for a in input().split())
B = list(int(b) for b in input().split())
la = len(A)
lb = len(B)
T = 0
r = 0
ans = 0
def dfs(i, j, T, r):
    global ans
    ans = max(ans, r)
    if i < la and T+A[i] <= K:
        dfs(i+1, j, T+A[i], r+1)
    if j < lb and T+B[j] <= K:
        dfs(i, j+1, T+B[j], r+1)

dfs(0, 0, T, 0)
print(ans)

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()))
totalbook = 0
totaltime = 0
for a in range(200000):
    if A == []:
        tt = B.pop(0)
    elif B == []:
        tt = A.pop(0)
    else:
        if A[0] <= B[0]:
            tt = A.pop(0)
        else:
            tt = B.pop(0)
        if totaltime + tt <= K:
            totaltime += tt
            totalbook += 1
        else:
            break
print(totalbook)

Submission status: Runtime Error

Solution code:
# Problem C - Tsundoku

# input
N, M, K = map(int, input().split())
a_nums = list(map(int, input().split()))
b_nums = list(map(int, input().split()))

# initialization
a_i = -1
b_i = -1
max_count = 0
cur_count = 0

# dfs search
def dfs(a_i, b_i):
    global max_count
    global cur_count
    global K

    if a_i>=N or b_i>=M:
        if cur_count>max_count:
            max_count = cur_count
        return

    # right check
    if a_i+1<N:
        if K - a_nums[a_i+1]>=0:
            K -= a_nums[a_i + 1]
            cur_count += 1
            dfs(a_i+1, b_i)
            cur_count -= 1
            K += a_nums[a_i + 1]
        else:
            if cur_count>max_count:
                max_count = cur_count
    else:
        if cur_count>max_count:
            max_count = cur_count

    # left check
    if b_i + 1<M:
        if K - b_nums[b_i + 1]>=0:
            K -=b_nums[b_i + 1]
            cur_count += 1
            dfs(a_i, b_i+1)
            cur_count -= 1
            K += b_nums[b_i + 1]
        else:
            if cur_count>max_count:
                max_count = cur_count
    else:
        if cur_count>max_count:
            max_count = cur_count

dfs(a_i, b_i)

# output
print(max_count)

Submission status: Runtime Error

Solution code:
n, m, k = [int(s) for s in input().split(" ")]
alist = [int(s) for s in input().split(" ")]
blist = [int(s) for s in input().split(" ")]

def max_inds(aind, bind, cur_time, k):
  if aind < len(alist) and bind < len(blist) and cur_time + alist[aind] > k and cur_time + blist[bind] > k:
    return aind + bind
  else:
    if aind < len(alist) and cur_time + alist[aind] <= k:
      t1 = max_inds(aind + 1, bind, cur_time + alist[aind], k)
    else:
      t1 = aind + bind
    if bind < len(blist) and cur_time + blist[bind] <= k:
      t2 = max_inds(aind, bind + 1, cur_time + blist[bind], k)
    else:
      t2 = aind + bind
    return max(t1, t2)

print(max_inds(0, 0, 0, k))

Submission status: Runtime Error

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

a_sum = 0
a_i = 0
flag = 0
for i in range(len(a)):
    if a_sum+a[i] <= k:
        a_sum += a[i]
    elif a_sum+a[i] > k:
        a_i = i-1
        break
if i == len(a)-1:
    a_i = len(a)-1

b_sum = 0
flag = 0
for i in range(len(b)):
    if b_sum+b[i] <= k:
        b_sum += b[i]
    elif b_sum+b[i] > k:
        b_i = i-1
        break
if i == len(b)-1:
    b_i = len(b)-1

ans = 0
temp = 0
a_temp = 0
b_temp = 0
if k < a[0] and k < b[0]:
    print(0)
else:
    while (k > a_sum or k > b_sum) and (a_sum > 0 or b_sum > 0):
        if (a_sum <= b_sum and a_sum > 0) or b_sum == 0:
            ans += 1
            k -= a[a_temp]
            a_sum -= a[a_temp]
            a_temp += 1
        elif b_sum > 0:
            ans += 1
            k -= b[b_temp]
            b_sum -= b[b_temp]
            b_temp += 1
        while a_sum > k and a_i != a_temp:
            a_sum -=a[a_i]
            if a_sum < 0:
                a_sum = 0
            a_i -= 1
        while b_sum > k and b_i != b_temp:
            b_sum -=b[b_i]
            if b_sum < 0:
                b_sum = 0
            b_i -= 1
    print(ans)

Submission status: Runtime Error

Solution code:
n, m, k = map(int, input().split())
*A, = map(int, input().split())
*B, = map(int, input().split())
A.append(0)
B.append(0)
time = 0
cnt = 0
a, b = 0, 0
while (a < m and time + A[a] <= k) or (b < n and time + B[b] <= k):
    if (a < m and time + A[a] <= k) and (b < n and time + B[b] <= k):
        if A[a] <= B[b]:
            cnt += 1
            time += A[a]
            a += 1
        else:
            cnt += 1
            time += B[b]
            b += 1
    elif (a < m and time + A[a] <= k):
        cnt += 1
        time += A[a]
        a += 1
    else:
        cnt += 1
        time += B[b]
        b += 1
print(cnt)

Submission status: Runtime Error

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

time = 0
maxBooks = 0
for i in range(N):
  if K - time >= A[i]:
    time += A[i]
    maxBooks += 1
  else:
    break

A_count = maxBooks
nowBooks = maxBooks

for i in range(M):
  if K - time >= B[i]:
    time += B[i]
    nowBooks += 1
  else:
    if A_count < 0:
      break
    while K - time < B[i]:
      time -= A[A_count]
      A_count -= 1
      nowBooks -= 1
    time += B[i]
    nowBooks += 1
  if maxBooks < nowBooks:
    maxBooks = nowBooks
    
print(maxBooks)

Submission status: Runtime Error

Solution code:
import sys
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
prog=0
a_idx=0
b_idx=0

while a_idx<n:
    if a[a_idx]+prog>k:
        break
    prog+=a[a_idx]
    a_idx+=1

if a_idx==n:
    while b_idx<m:
        if b[b_idx]+prog>k:
            break
        prog+=b[b_idx]
        b_idx+=1

mx=a_idx+b_idx

if mx==n+m:
    print(mx)
    sys.exit()

for i in range(a_idx):
    while b[b_idx]+prog<=k:
        prog+=b[b_idx]
        b_idx+=1
    if a_idx+b_idx>mx:
        mx=a_idx+b_idx
    a_idx-=1
    prog-=a[a_idx]

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()))
ans=0
count=0
a=0
b=0

while count<k:
    if A[a]<B[b]:
        if k-count>=A[a]:
            count+=A[a]
            ans+=1
            if a<len(A)-1:
                a+=1
            else:
                A[a]=10**10
        else:
            print(ans)
            break
                
    if A[a]>B[b]:
        if k-count>=B[b]:
            count+=B[b]
            ans+=1
            if b<len(B)-1:
                b+=1
            else:
                B[b]=10**10
    
        else:
            print(ans)
            break
    
    if A[a]==B[b]:
        if k-count>=B[b]:
            if A[a+1]<B[b+1]:
                count+=A[a]
                ans+=1
                if a<len(A)-1:
                    a+=1
                else:
                    A[a]=10**10
            else:
                count+=B[b]
                ans+=1
                if b<len(B)-1:
                    b+=1
                else:
                    B[b]=10**10
        else:
            print(ans)
            break

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

cnt = 0
time = 0
a = A.popleft()
b = B.popleft()

while time <= K:
    if a == b == 10**9 + 1:
        break

    if a == b:
        for i in range(min(len(A), len(B))):
            if A[i] < B[i]:
                judge = 'A'
                break
            elif A[i] > B[i]:
                judge = 'B'
                break

        if judge == 'A':
            time += a
            try:
                a = A.popleft()
            except:
                a = 10 ** 9 + 1
        else:
            time += b
            try:
                b = B.popleft()
            except:
                b = 10 ** 9 + 1
    elif a < b:
        time += a
        try:
            a = A.popleft()
        except:
            a = 10**9 + 1
    else:
        time += b
        try:
            b = B.popleft()
        except:
            b = 10**9 + 1

    if time > K:
        break

    cnt += 1

print(cnt)

Submission status: Runtime Error

Solution code:
import numpy as np

n, m, k = [int(e) for e in input().split()]
a = np.array([int(e) for e in input().split()])
b = np.array([int(e) for e in input().split()])

asum = a.cumsum()
bsum = b.cumsum()

onlya = (asum < k).sum()
onlyb = (bsum < k).sum()
ans = max(onlya,onlyb)

xs,ys = np.meshgrid(asum,bsum)
nums = list(zip(*np.where(xs+ys <= k)))
for i in nums:
    if i[0]+i[1]+2 > ans:
        ans = i[0]+i[1]+2

print(ans)

Submission status: Runtime Error

Solution code:
import sys

sys.setrecursionlimit( 10 * 10 )

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

a.append( 10 ** 9 + 1 )
b.append( 10 ** 9 + 1 )

def dp( i, j, t ):
    next_i = min( i+1, n )
    next_j = min( j+1, m )
    if i == n and j == m:
        return 0
    elif a[ i ] + t > k and b[ j ] + t > k:
        return 0
    elif a[ i ] + t > k:
        return dp( i, next_j, t+b[j] ) + 1
    elif b[ j ] + t > k:
        return dp( next_i, j, t+a[i] ) + 1
    else:
        return max( dp( next_i, j, t+a[i] ), dp( i, next_j, t+b[j] ) ) + 1

read = dp( 0, 0, 0 )
    
print( read )

Submission status: Runtime Error

Solution code:
import numpy as np

N, M, K = map(int, input().split())
A = input().split()
B = input().split()
for i in range(len(A)):
  A[i] = int(A[i])
for i in range(len(B)):
  B[i] = int(B[i])
A_cumsum = np.array(A).cumsum()
B_cumsum = np.array(B).cumsum()
max_count = 0
for i in range(M):
  if B_cumsum[i] <= K and max_count <= B_cumsum[i]:
    max_count = i + 1
  else:
    break
for i in range(M):
  if A_cumsum[i] <= K and max_count <= A_cumsum[i]:
    max_count = i + 1
  else:
    break
for i in range(N):
  if A_cumsum[i] > K:
    break
  for j in range(M):
    if A_cumsum[i] + B_cumsum[j] <= K and max_count <= A_cumsum[i] + B_cumsum[j]:
      max_count = i + j + 2
    else:
      break
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()))
aot = []
i, j = 0, 0
while sum(aot) < k:


  if len(a) > 0 and len(b) > 0:
    if a[i] >= b[j]:
      aot.append(b[j])
      del b[j]
      #print('aは{}, bは{}'.format(a, b))
    elif a[i] <= b[j]:
      aot.append(a[i])
      del a[i]
      #print('aは{}, bは{}'.format(a, b))
      
  elif len(a) == 0:
    aot.append(b[j])
    del b[j]
  elif len(b) == 0:
    aot.sppend(a[i])
    del a[i]
  
if sum(aot) > k:
  del aot[-1]
print(len(aot))

Submission status: Runtime Error

Solution code:

n, m, k = (int(x) for x in input().split())

n_list = list(map(int, input().split()))
m_list = list(map(int, input().split()))

count = 0

i = 0

# 全て読み切れる
if(sum(n_list + m_list) <= k) :
    count = n + m
# どこかで時間切れになる
else :
    while k > 0 :

        k = k - n_list[i]
        if 0 <= k :
            count += 1

            k = k - m_list[i]
            if 0 <= k :
                count += 1

        i += 1

print(count)

Submission status: Runtime Error

Solution code:
def dfs(a, b, k):
    nonlocal cnt
    seen[a][b] = True
    na = a + 1
    nb = b + 1
    if na <= N and seen[na][b] is False and k >= book_a[na]:
        k -= book_a[na]
        cnt = max(cnt, na + b)
        dfs(na, b, k)
    if nb <= M and seen[a][nb] is False and k >= book_b[nb]:
        k -= book_b[nb]
        cnt = max(cnt, a + nb)
        dfs(a, nb, k)
        
N, M, k = map(int, input().split())
book_a = [int(x) for x in input().split()]
book_b = [int(x) for x in input().split()]
book_a.insert(0, 0)
book_b.insert(0, 0)
cnt = 0
seen = [[False] * (M + 1) for _ in range(N + 1)]
dfs(0, 0, k)
print(cnt)

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]:
    books += 1
    if a[ai] < b[bi]:
        minute += a[ai]
        if len(a) >= ai + 1:
            an = 1000000000
        else:
            ai += 1
    elif b[bi] < a[ai]:
        minute += b[bi]
        bi += 1
        if len(b) <= bi + 1:
            bn = 1000000000
        else:
            bi += 1
    else:
        minute += a[ai]
        if len(a) >= ai + 1:
            an = 1000000000
        elif len(a) < ai + 1:
            ai += 1
        elif len(b) <= bi + 1:
            bn = 1000000000
        elif len(b) > bi + 1:
            bi += 1
        else:
            books += 1
            break

print(books-1)

Submission status: Runtime Error

Solution code:
nmk = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))

c = 0
ans = 0
while ans <= nmk[2]:
    
    c += 1
    
    x = min(A[0], B[0])
    pre_ans = ans
    ans += x
    
    if ans - A[0] == pre_ans:
        B.pop(0)
    
    elif ans - B[0] == pre_ans:
        A.pop(0)

print(c)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
# atcoder 
# Türkler var mı?
# Herkese memnün oldum
import sys

iimr = lambda: map(int, sys.stdin.readline().rstrip().split())
readline = sys.stdin.readline
sys.setrecursionlimit(10 ** 8)


def 関数(n, m, k, n_liste, m_liste):
    temps = 0
    i = j = 0
    satsu = 0
    
    n_liste.sort()
    nlen = len(n_liste)
    m_liste.sort()
    mlen = len(m_liste)

    if k < n_liste[i] and k < m_liste[j]:
        return satsu

    while(temps <= k):
        if(n_liste[i] <= m_liste[j]):
            temps += n_liste[i]
            if(i+1 < nlen):
                i += 1
        else:
            temps += m_liste[i]
            if(j+1 < mlen):
                j += 1
        satsu += 1
    return satsu-1

def çözmek():
    N, M, K = map(int, sys.stdin.readline().split())
    A = list(map(int, sys.stdin.readline().split()))
    B = list(map(int,sys.stdin.readline().split()))
    res = []
    res.append(関数(N, M, K, A, B))
    print(*res, sep="\n")

if __name__ == "__main__":
    çözmek()

Submission status: Runtime Error

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

A_sum = [0]
B_sum = [0]

for a in A_list:
    A_sum.append(A_sum[-1] + a)

for b in B_list:
    B_sum.append(B_sum[-1] + b)

count = 0


def solve(i, j):
    global count
    if A_sum[i] + B_sum[j] > K:
        return
    if count < i + j:
        count = i + j
    if i == len(A_sum) - 1 and j == len(B_sum) - 1:
        return
    elif i == len(A_sum) - 1:
        solve(i, j + 1)
    elif j == len(B_sum) - 1:
        solve(i + 1, j)
    else:
        solve(i + 1, j)
        solve(i, j + 1)


solve(0, 0)
print(count)

Submission status: Runtime Error

Solution code:
def main():
    n, m, k = map(int, input().split())
    alis = list(map(int, input().split()))
    blis = list(map(int, input().split()))
    adic = {}
    bdic = {}
    for i in range(len(alis)):
        adic[i+1] = alis[i]
    for i in range(len(blis)):
        bdic[i+1] = blis[i]

    time = 0
    ans = 0
    a = 1
    b = 1
    while time <= k:
        #print(alis, blis, len(alis), k, time)
        if a > len(adic) and b > len(bdic):
            break
        elif a > len(adic) and bdic[b] <= k - time:
            time += bdic[b]
            b += 1
            ans += 1
        elif b > len(bdic) and adic[a] <= k - time:
            time += adic[a]
            a += 1
            ans += 1
        elif a > len(adic) and bdic[b] > k - time:
            break
        elif b > len(bdic) and adic[a] > k - time:
            break
        
        else:
            #print(alis, blis)
            if adic[a] < bdic[b] and time + adic[a] <= k:
                #print(a, adic[a], b, bdic[b], time, k)
                time += adic[a]
                a += 1
                ans += 1
                #print(a, adic[a], b, bdic[b], time, k)
            elif adic[a] > bdic[b] and time + bdic[b] <= k:
                #print(a, adic[a], b, bdic[b], time, k)
                #print(time)
                time += bdic[b]
                b += 1
                ans += 1
                #print(a, adic[a], b, bdic[b], time, k)
            elif adic[a] == bdic[b] and time + adic[a] <= k:
                if adic[a+1] < bdic[b+1]:
                    time += adic[a]
                    a += 1
                    ans += 1
                else:
                    time += bdic[b]
                    b += 1
                    ans += 1
            else:
                break


    print(ans)

    
if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
deta = list(input().split(" "))
ahon = int(deta[0])
bhon = int(deta[1])
time = int(deta[2])

alist = list(input().split(" "))
blist = list(input().split(" "))
alist.append("10000000000")
blist.append("10000000000")

book = 0
a = 0
b = 0
while time > 0:
    for i in range(200000):
        if int(alist[a+i]) == int(blist[b+i]):
            continue
        else:
            break
    if int(alist[a+i]) <= int(blist[b+i]):
        if int(alist[a]) > time:
            break
        else:
            time -= int(alist[a])
            book += 1
            a += 1
    elif int(alist[a+i]) > int(blist[b+i]):
        if int(blist[b]) > time:
            break
        else:
            time -= int(blist[b])
            book += 1
            b += 1

print(book)

Submission status: Runtime Error

Solution code:
from sys import stdin, stdout
import heapq
import cProfile
from collections import Counter, defaultdict, deque
from functools import reduce
import math
from bisect import bisect, bisect_right, bisect_left


def get_int():
    return int(stdin.readline().strip())


def get_tuple():
    return map(int, stdin.readline().split())


def get_list():
    return list(map(int, stdin.readline().split()))

save = 0
def fun(n, m, k, ans):
    global mx, a, b, dp,save

    mx = max(mx, ans)

    if n <= 0 and m <= 0 or k <= 0:
        return ans

    key = str(n)+"_"+str(m)+"_"+str(k)
    if key in dic:
        save += 1
        return dic[key]

    x, y = -100, -100
    if n > 0 and a[n - 1] <= k:
        key1 = str(n-1)+"_"+str(m)+"_"+str(k - a[n - 1])
        x = fun(n - 1, m, k - a[n - 1], ans + 1)
        dic[key1] = x
    if m > 0 and b[m - 1] <= k:
        key2 = str(n) + "_" + str(m-1) + "_" + str(k - b[m - 1])
        y = fun(n, m - 1, k - b[m - 1], ans + 1)
        dic[key2] = y

    dic[key] = max(x,y)
    return max(x, y)


mx = 0
n, m, k = get_tuple()
dic = defaultdict(int)
a = get_list()
b = get_list()
a = a[::-1]
b = b[::-1]
fun(n, m, k, 0)
print(mx)

Submission status: Runtime Error

Solution code:
import bisect

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

#現在のインデックス
idx_a=0
idx_b=0

while idx_a<n or idx_b<m:
    read=''
    #aの読める数
    oset_a=sum_a[idx_a-1] if idx_a>0 else 0
    can_cnt_a=bisect.bisect_right(sum_a,k+oset_a)
    #bの読める数
    oset_b=sum_b[idx_b-1] if idx_b>0 else 0
    can_cnt_b=bisect.bisect_right(sum_b,k+oset_b)
    read='a' if can_cnt_a-idx_a>can_cnt_b-idx_b else 'b'
    

    #読むほうをPOP
    k-=a[idx_a] if read=='a' else b[idx_b]
    #kを超えた場合ブレーク
    if k<0:
        break
    #カウントアップ
    if read=='a':
        idx_a+=1
    else:
        idx_b+=1
print(idx_a+idx_b)

Submission status: Runtime Error

Solution code:
def Tsundoku():

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

    value_A = list(map(int,input().split()))
    value_B = list(map(int,input().split()))

    total_time = 0
    total_num = 0
    
    numA = 0
    numB = 0
    
    if value_A[numA] + total_time < Num[2] or value_B[numB] + total_time < Num[2]:
    
        while value_A[numA] + total_time < Num[2] or value_B[numB] + total_time < Num[2]:
    
            if len(value_A) == numA and len(value_B) == numB:
                break
            
            elif len(value_B) != numB and len(value_A) != numA and value_A[numA] > value_B[numB]:
                total_time = total_time + value_B[numB]
                numB = numB + 1
                total_num = total_num + 1
                
            elif len(value_A) != numA and len(value_B) != numB and value_A[numA] <= value_B[numB]:
                total_time = total_time + value_A[numA]
                numA = numA + 1
                total_num = total_num + 1            
            
        
            elif len(value_A) == numA and total_time < total_time + value_B[numB]:
                total_time = total_time + value_B[numB]
                numB = numB + 1
                total_num = total_num + 1
                
            elif len(value_B) != numB and total_time < total_time + value_A[numA]:
                total_time = total_time + value_A[numA]
                numA = numA + 1
                total_num = total_num + 1

        print(total_num)

    else:
        print(total_num)


if __name__ == '__main__':
    Tsundoku()

Submission status: Runtime Error

Solution code:
N,M,K = list(map(int,input().split()))
A=list(map(int,input().split()))
B=list(map(int,input().split()))
a=0
b=0
count=0
kazu=0
time=0
A1=list()
A1.append(0)
B1=list()
B1.append(0)
mA=0
mB=0
for i in range(len(A)):
    mA+=A[i]
    A1.append(mA)
for i in range(len(B)):
    mB+=B[i]
    B1.append(mB)   
Ak=len(A1)-1
Bk=len(B1)-1

count=Ak+Bk
t=0
f=0
while True:
    for i in range(f+1):
        if A1[Ak-i]+B1[count-(Ak-i)]<=K:
            ans=count
            t=1
            break
    
    if t==1:
        break
    count-=1
    if count==0:
        ans=0
        break
    f+=1

print(ans)