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:
# ==================================================-
# 二分探索
# functionを満たす,search_listの最大の要素を出力
# 【注意点】searchリストの初めの方はfunctionを満たし、後ろに行くにつれて満たさなくなるべき
import math
import sys

sys.setrecursionlimit(10 ** 9)


def binary_research(start, end, search_list, function):
    if start == end:
        return search_list[start]
    middle = math.ceil((start + end) / 2)
    if function(search_list[middle], k, a_sum, b_sum):
        start = middle
    else:
        end = middle - 1
    return binary_research(start, end, search_list, function)


# ==================================================-

n, m, k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
a_sum = [0]
b_sum = [0]
for book in a:
    a_sum.append(a_sum[-1] + book)
for book in b:
    b_sum.append(b_sum[-1] + book)


def can_read(num, k, a_sum, b_sum):
    min_read_time = 1000000000000
    for i in range(max(0, num - m), n + 1):
        a_num = i
        b_num = num - i
        min_read_time = min(min_read_time, a_sum[a_num] + b_sum[b_num])
    if min_read_time <= k:
        return True
    return False


search_list = list(range(n + m + 1))
start = 0
end = n + m

print(binary_research(start, end, search_list, can_read))

Submission status: Runtime Error

Solution code:
# ==================================================-
# 二分探索
# functionを満たす,search_listの最大の要素を出力
# 【注意点】searchリストの初めの方はfunctionを満たし、後ろに行くにつれて満たさなくなるべき
import math
import sys

sys.setrecursionlimit(10 ** 9)


def binary_research(start, end, search_list, function):
    if start == end:
        return search_list[start]
    middle = math.ceil((start + end) / 2)
    if function(search_list[middle], k, a_sum, b_sum):
        start = middle
    else:
        end = middle - 1
    return binary_research(start, end, search_list, function)


# ==================================================-

n, m, k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
a_sum = [0]
b_sum = [0]
for book in a:
    a_sum.append(a_sum[-1] + book)
for book in b:
    b_sum.append(b_sum[-1] + book)


def can_read(num, k, a_sum, b_sum):
    min_read_time = 1000000000
    for i in range(max(0, num - m), n + 1):
        a_num = i
        b_num = num - i
        min_read_time = min(min_read_time, a_sum[a_num] + b_sum[b_num])
    if min_read_time <= k:
        return True
    return False


search_list = list(range(n + m + 1))
start = 0
end = n + m

print(binary_research(start, end, search_list, can_read))

Submission status: Runtime Error

Solution code:
# ==================================================-
# 二分探索
# functionを満たす,search_listの最大の要素を出力
# 【注意点】searchリストの初めの方はfunctionを満たし、後ろに行くにつれて満たさなくなるべき
import math
import sys
sys.setrecursionlimit(10**9)

def binary_research(start,end,search_list,function):
    if start==end:
        return search_list[start]
    middle=math.ceil((start+end)/2)
    if function(search_list[middle],k,a_sum,b_sum):
        start=middle
    else:
        end=middle-1
    return binary_research(start, end, search_list, function)

# ==================================================-

n,m,k=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
a_sum=[0]
b_sum=[0]
for book in a:
    a_sum.append(a_sum[-1]+book)
for book in b:
    b_sum.append(b_sum[-1]+book)


def can_read(num,k,a_sum,b_sum):

    min_read_time=1000000000000000
    for i in range(max(0,num-m),n+1):
        a_num=i
        b_num=num-i
        min_read_time=min(min_read_time,a_sum[a_num]+b_sum[b_num])
    if min_read_time<=k:
        return True
    return False

search_list=list(range(n+m+1))
start=0
end=n+m

print(binary_research(start,end,search_list,can_read))

Submission status: Runtime Error

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

def binary_research(start,end,search_list,function):
    if start==end:
        return search_list[start]
    middle=math.ceil((start+end)/2)
    if function(search_list[middle],k,a_sum,b_sum):
        start=middle
    else:
        end=middle-1
    return binary_research(start, end, search_list, function)

# ==================================================-

n,m,k=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
a_sum=[0]
b_sum=[0]
for book in a:
    a_sum.append(a_sum[-1]+book)
for book in b:
    b_sum.append(b_sum[-1]+book)


def can_read(num,k,a_sum,b_sum):

    min_read_time=1000000000000000
    for i in range(max(0,num-m),n+1):
        a_num=i
        b_num=num-i
        min_read_time=min(min_read_time,a_sum[a_num]+b_sum[b_num])
    if min_read_time<=k:
        return True
    return False

search_list=list(range(n+m+1))
start=0
end=n+m

print(binary_research(start,end,search_list,can_read))

Submission status: Runtime Error

Solution code:
# ==================================================-
# 二分探索
# functionを満たす,search_listの最大の要素を出力
# 【注意点】searchリストの初めの方はfunctionを満たし、後ろに行くにつれて満たさなくなるべき
import math
def binary_research(start,end,search_list,function):
    if start==end:
        return search_list[start]
    middle=math.ceil((start+end)/2)
    if function(search_list[middle],k,a_sum,b_sum):
        start=middle
    else:
        end=middle-1
    return binary_research(start, end, search_list, function)

# ==================================================-

n,m,k=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
a_sum=[0]
b_sum=[0]
for book in a:
    a_sum.append(a_sum[-1]+book)
for book in b:
    b_sum.append(b_sum[-1]+book)


def can_read(num,k,a_sum,b_sum):

    min_read_time=1000000000000000
    for i in range(max(0,num-m),n+1):
        a_num=i
        b_num=num-i
        min_read_time=min(min_read_time,a_sum[a_num]+b_sum[b_num])
    if min_read_time<=k:
        return True
    return False

search_list=list(range(n+m+1))
start=0
end=n+m

print(binary_research(start,end,search_list,can_read))

Submission status: Runtime Error

Solution code:
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = a[::-1] + b
d = [0] * (len(c)+1)
for i in range(len(c)):
    d[i+1] = d[i] + c[i]
l = 0
r = 0
mx = 0
while r < len(d) and l <= n:
    if (d[r+1] - d[l] <= k):
        r += 1
    else:
        l += 1
        if l > r:
            r = l
    if mx < r - l:
        mx = r-l

print(mx)

Submission status: Runtime Error

Solution code:
from itertools import accumulate
N, M, K = map(int,input().split())
A_list = [0] + list(map(int,input().split()))
B_list = [0] + list(map(int,input().split()))
A_sums_list = list(accumulate(A_list))
B_sums_list = list(accumulate(B_list))

for n in range(N + 1):
    if A_sums_list[n] > K:
        break
    A_max = n
for m in range(M + 1):
    if B_sums_list[m] > K:
        break
    B_max = m
ans = max(A_max, B_max)

for i in reversed(range(A_max + 1)):
    for j in reversed(range(ans - i + 2)):
        if i + j > ans:
            if A_sums_list[i] + B_sums_list[j] <= K:
                ans = i + j
                break
        else:
            break
print(ans)

Submission status: Runtime Error

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

ans=0
time=0
a=0
b=0
while time<K:
  if A[a]<=B[b]:
    time+=A[a]
    a+=1
    ans+=1
  else:
    time+=B[b]
    b+=1
    ans+=1
print(ans)

Submission status: Runtime Error

Solution code:
import itertools

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

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

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

print(ans)

Submission status: Runtime Error

Solution code:
# ABC C-Tsundoku
n,m,k = map(int,input().split())
an = list(map(int,input().split()))
bn = list(map(int,input().split()))

suma = [0]
sumb = [0]
a = 0
b = 0
for i in an:
    a += i
    suma.append(a)
for i in bn:
    b += i
    sumb.append(b)

res = [0]
for j in range(n+1):
    if k-suma[j] < 0:
        break
    for l in range(m+1):
        if k-suma[j]-sumb[l] > 0:
        res.append(j+l)
print(max(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()))
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:
# ABC C-Tsundoku
n,m,k = map(int,input().split())
an = list(map(int,input().split()))
bn = list(map(int,input().split()))

ans = 0
flag = False
suma = []
sumb = []
a = 0
b = 0
for i in an:
    a += i
    if a <= k:
        suma.append(a)
    else:
        break
for i in bn:
    b += i
    if b <= k:
        sumb.append(b)
    else:
        break
suma = suma[::-1]
res = []
for j,l in enumerate(suma):
    dif = k-l
    for o,p in enumerate(sumb):
        if p <= dif:
            res.append(len(suma)-j+o+1)
        else:
            break
            
print(max(res))

Submission status: Runtime Error

Solution code:
N,M,K = map(int, input().split())
A_list = [int(e) for e in input().split()] #N
B_list = [int(e) for e in input().split()] #M

#ABの読む順序は関係ない
A_list = A_list[::-1]
B_list = B_list[::-1]

A_readed_books = list()

#まずAをずっと読んだ時の最大冊数を求める
reading_time_sum = 0
read_books_num = 0

while 1:
    if reading_time_sum + A_list[-1] <= K:
        reading_time_sum += A_list[-1]
        read_books_num += 1
        A_readed_books.append(A_list.pop(-1))
        if len(A_list) == 0:
            break
    else:
        break

read_books_num_max = read_books_num
B_readed_books = list()

#Aを全部読んでも余裕があるならBも読む
if reading_time_sum < K:
    while 1:
        if reading_time_sum + B_list[-1] <= K:
            reading_time_sum += B_list[-1]
            B_readed_books.append(B_list.pop(-1))
            read_books_num += 1
            if len(B_list) == 0:
                break
        else:
            break

if len(B_list) == 0:
    print(read_books_num) #全部読める
else:
    read_books_num_max = read_books_num
    
    while 1:
        #Aの読む冊数を減らして、
        if len(A_readed_books)!=0:
            last_readed_books = A_readed_books.pop(-1)
            reading_time_sum -= last_readed_books
            read_books_num -= 1
            #Bに割り当てて冊数の増加を試す
            while 1:
                if B_list[-1] + reading_time_sum <= K:
                    reading_time_sum += B_list[-1]
                    B_readed_books.append(B_list.pop(-1))
                    read_books_num += 1
                    if len(B_list)==0:
                       if read_books_num_max < read_books_num:
                            read_books_num_max = read_books_num
                        print(read_books_num_max)
                        exit()
                else:
                    break
            if read_books_num_max < read_books_num:
                read_books_num_max = read_books_num

    print(read_books_num_max)

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.reverse()
B.reverse()
count = 0
time = 0

if sum(A)+sum(B) <= K :
    print(len(A)+len(B))
    exit()

if K < A[-1] and K < B[-1] :
    print(0)
    exit()

while time <= K :
    # print(A,B)
    # print(time)
    if len(A) == 0 or len(B) == 0 :
        t = A if len(B) == 0 else B
        time += t[-1]
        del t[-1:]
        count += 1
        continue
    if A[-1] == B[-1] :
        i = 0
        while A[-(1+i)] == B[-(1+i)] :
            time += A[-(1+i)]
            count += 1
            i += 1
        else :
            consumedTower = A if A[-(1+i)] < B[-(1+i)] else B
            del consumedTower[-i:]
    elif A[-1] < B[-1] :
        time += A[-1]
        del A[-1:]
        count += 1
    else :
        time += B[-1]
        del B[-1:]
        count += 1

print(count-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()))
ab_sum , answer, b_i = sum(B), 0, M
for a_i in range(N+1):
  while b_i>0 and ab_sum >K:
    b_i -= 1
    ab_sum -= B[b_i]
  if ab_sum >K:
    break
  answer = max(answer, a_i+b_i)
  ab_sum += A[a_i]

print(answer)

Submission status: Runtime Error

Solution code:
def greather_than(tableA, curr_a_index, tableB, curr_b_index, rem_a, rem_b):
  while rem_a != 0 and rem_b != 0 and tableA[curr_a_index] == tableB[curr_index]:
    curr_a_index += 1
    curr_b_index += 1
    rem_a -= 1
    rem_b -= 1
  if rem_a == 0 and rem_b == 0:
    return True
  elif rem_a == 0:
    return False
  elif rem_b == 0:
    return True
  else:
    return tableA[curr_a_index] > tableB[curr_index]



[N, M, K] = map(int, input().split())
tableA = input().split()
tableB = input().split()
total_min = 0

curr_a_index = 0
curr_b_index = 0

rem_a = N
rem_b = M

while curr_a_index < N or curr_b_index < M:
  if total_min > K:
    break
  else:
    if rem_a == 0 and rem_b == 0:
      break
    elif rem_a == 0:
      total_min += int(tableB[curr_b_index])

      if total_min > K:
        break

      curr_b_index += 1
      rem_b -= 1
    elif rem_b == 0:
      total_min += int(tableA[curr_a_index])

      if total_min > K:
        break

      curr_a_index += 1
      rem_a -= 1
    else:
      if int(tableA[curr_a_index]) > int(tableB[curr_b_index]):
        total_min += int(tableB[curr_b_index])

        if total_min > K:
          break

        curr_b_index += 1
        rem_b -= 1
      elif int(tableA[curr_a_index]) < int(tableB[curr_b_index]):
        total_min += int(tableA[curr_a_index])

        if total_min > K:
          break

        curr_a_index += 1
        rem_a -= 1
      else:
        if greather_than(tableA, curr_a_index, tableB, curr_b_index, rem_a, rem_b):
          total_min += int(tableB[curr_b_index])

          if total_min > K:
            break

          curr_b_index += 1
          rem_b -= 1
        else:
          total_min += int(tableA[curr_a_index])

          if total_min > K:
            break

          curr_a_index += 1
          rem_a -= 1

print(curr_a_index + curr_b_index)

Submission status: Runtime Error

Solution code:
n,m,k = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
x = A+B
s,t = 0,len(A)
total, cnt = 0,0
if min(x) > k:
    print(0)
else:
    while cnt < len(x):
        if total +min(x[s],x[t]) >= k:
            break
        else:
            if x[s] < x[t]:
                total += x[s]
                s += 1
            else:
                total += x[t]
                t += 1
            cnt += 1

    print(cnt)

Submission status: Runtime Error

Solution code:
n,m,k = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
x = A+B
s,t = 0,len(A)
total, cnt = 0,0
if min(x) > k:
    print(0)
else:
    while cnt < len(x):
        if total +min(x[s],x[t]) > k:
            break
        else:
            if x[s] < x[t]:
                total += x[s]
                s += 1
            else:
                total += x[t]
                t += 1
            cnt += 1

    print(cnt)

Submission status: Runtime Error

Solution code:
n,m,k = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
x = A+B
s,t = 0,len(A)
total, cnt = 0,0
while cnt < len(x):
    if total +min(x[s],x[t]) > k:
        break
    else:
        if x[s] < x[t]:
            total += x[s]
            s += 1
        else:
            total += x[t]
            t += 1
        cnt += 1

print(cnt)

Submission status: Runtime Error

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

total = 0
Asum = sum(A)
nA = len(A)
Bsum = 0
ans = 0
for nB in range(len(B) + 1):
    if nB != 0:
        Bsum += B[nB-1]
    while Asum + Bsum > K:
        nA -= 1
        Asum -= A[nA]
    ans = max(nA + nB, ans)

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()))
cnt1 = 0
cnt2 = 0
  
while cnt1 < k:
  if ( m == 0 or a[0] <= b[0] ) and n != 0:
    cnt1 += a[0]
    cnt2 += 1
    n -= 1
    del a[0]
    
  elif (n == 0  or a[0] > b[0] ) and m != 0:
    cnt1 += b[0]
    cnt2 += 1
    m -= 1
    del b[0]

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

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])
    
v,j=0,M

for i in range(N+1):
    if a[i]>K:
        break
    while b[j]>K-a[i]:
        j-=1
    v=max(b,i+j)

print(v)

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

int main(){
        int i,ans,ia,ib=0;
        ll n,m,k,A,B;
        cin >> n >> m >> k;
        vector<ll> a(n+1);
        vector<ll> b(m+1);
        for(i=1;i<n;++i){
                cin >> A;
                a.at(i) = a.at(i-1)+A;
        }
        for(i=1;i<m;++i){
                cin >> B;
                b.at(i) = b.at(i-1)+B;
        }
        for(i=n-1;i>0;--i){
                if(a.at(i)<=k){
                        ans = i;
                        ia = i;
                        break;
                }
        }
        while(ia>=0){
                while(a.at(ia)+b.at(ib)<=k){
                        ++ib;
                }
                --ib;
                ans = max(ans, ia+ib);
                --ia;
        }
        cout << ans << endl;
        return 0;
}

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

sum_A = 0
A_list = []
for i in range(len(A)):
    sum_A += A[i]
    A_list.append(sum_A)
    if sum_A>K:
        break
A = A[:i]

sum_B = 0
B_list = []
for i in range(len(B)):
    sum_B += B[i]
    B_list.append(sum_B)
    if sum_B>K:
        break
B = B[:i]

num = []
cost = []
if (len(A)==0)&(len(B)==0):
    ans = 0
elif (len(A)==0)&(len(B)!=0):
    ans = len(B)
elif (len(A)!=0)&(len(B)==0):
    ans = len(A)
else:
    for i in range(len(A)):
        for j in range(len(B)):
            if A_list[i]+B_list[j]>K:
                break
            else:
                num.append(i+j+2)
                cost.append(A_list[i]+B_list[j])
    num = np.array(num)
    cost = np.array(cost)
    num = num[cost<=K]
    cost = cost[cost<=K]
    ans = max(num)

print(ans)

Submission status: Runtime Error

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

sum_A = 0
A_list = []
for i in range(len(A)):
    sum_A += A[i]
    A_list.append(sum_A)
    if sum_A>=K:
        break
A = A[:i]
A_list = A_list[:i]

sum_B = 0
B_list = []
for i in range(len(B)):
    sum_B += B[i]
    B_list.append(sum_B)
    if sum_B>=K:
        break
B = B[:i]
B_list = B_list[:i]

num = []
cost = []
if (len(A)==0)&(len(B)==0):
    ans = 0
elif len(A)==0&len(B)!=0:
    ans = len(B)
elif len(A)!=0&len(B)==0:
    ans = len(A)
else:
    for i in range(len(A)):
        for j in range(len(B)):
            if A_list[i]+B_list[j]>K:
                break
            else:
                num.append(i+j+2)
                cost.append(A_list[i]+B_list[j])
    num = np.array(num)
    cost = np.array(cost)
    num = num[cost<=K]
    cost = cost[cost<=K]
    ans = max(num)

print(ans)

Submission status: Runtime Error

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

sum_A = 0
A_list = []
for i in range(len(A)):
    sum_A += A[i]
    A_list.append(sum_A)
    if sum_A>=K:
        break
A = A[:i]

sum_B = 0
B_list = []
for i in range(len(B)):
    sum_B += B[i]
    B_list.append(sum_B)
    if sum_B>=K:
        break
B = B[:i]
num = []
cost = []
if (len(A)==0)&(len(B)==0):
    ans = 0
elif len(A)==0&len(B)!=0:
    ans = len(B)
elif len(A)!=0&len(B)==0:
    ans = len(A)
else:
    for i in range(len(A)):
        for j in range(len(B)):
            if A_list[i]+B_list[j]>K:
                break
            else:
                num.append(i+j+2)
                cost.append(A_list[i]+B_list[j])
    num = np.array(num)
    cost = np.array(cost)
    num = num[cost<=K]
    cost = cost[cost<=K]
    ans = max(num)

print(ans)

Submission status: Runtime Error

Solution code:
a

Submission status: Runtime Error

Solution code:
N,M,K=map(int,input().split())
Ai=list(map(int,input().split()))
Bi=list(map(int,input().split()))
lis=[]
for i in range(N+M):
    if Ai[i]>Bi[i]:
        lis.append(Bi[i])
    else:
        lis.append(Ai[i])
        if sum(lis)>=K:
            break
print(len(lis))

Submission status: Runtime Error

Solution code:
N,M,K=map(int,input().split())
Ai=list(map(int,input().split()))
Bi=list(map(int,input().split()))
ldit=[]
for i in range(N+M):
    if A[i]>B[i]:
        list.append(B[i])
    else:
        list.append(A[i])
        if sum(list)>=K:
            break
print(len(list))

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_cumsum, B_cumsum = [0], [0]

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

for i, a in enumerate(A_cumsum):
    if a > k:
        break
    
    for j, b in enumerate(B_cumsum):
        if (a + b > k:
            break
        elif (i + j) < ans:
            pass
        else:
            ans = (i + j)

print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

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

A.insert(0, 0)
B.insert(0, 0)

A = np.array(A)
B = np.array(B)

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

ans = 0

for i, a in enumerate(A_cumsum):
    for j, b in enumerate(B_cumsum):
        n = i + j
        if n > ans:
            if a + b <= k:
                ans = n
            else:
                break

print(ans)

Submission status: Runtime Error

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


time = 0
ans = 0
a_next = a.pop(0)
b_next = b.pop(0)

while True:
        
    if a_next <= b_next:
        time += a_next
        try:
            a_next = a.pop(0)
        except:
            a_next = 200001
    
    else:
        time += b_next
        try:
            b_next = b.pop(0)
        except:
            b_next = 200001
    
    if time <= k:
        ans += 1
    else:
        break

print(ans)

Submission status: Runtime Error

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


time = 0
ans = 0

while time <= k:
    if a[0] < b[0]:
        time += a.pop(0)
        a.append(200001)
    elif a[0] > b[0]:
        time += b.pop(0)
        b.append(200001)
    else:
        if a[1] < b[1]:
            time += a.pop(0)
            a.append(200001)
        else:
            time += b.pop(0)
            b.append(200001)
    
    if time <= k:
        ans += 1
    else:
        break

print(ans)

Submission status: Runtime Error

Solution code:
n, m, k = map(int, input().split())
a = [a for a in input().split()]
b = [b for b in input().split()]

time = 0
ans = 0

while time <= k:
    if a[0] < b[0]:
        time += a.pop(0)
        a.append(200001)
    elif a[0] > b[0]:
        time += b.pop(0)
        b.append(200001)
    else:
        if a[1] < b[1]:
            time += a.pop(0)
            a.append(200001)
        else:
            time += b.pop(0)
            b.append(200001)
    
    if time <= k:
        ans += 1
    else:
        break

print(ans)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))
out = lambda x: print('\n'.join(map(str, x)))

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

Submission status: Runtime Error

Solution code:
import numpy as np
N,M,K = list(map(int,input().split()))
A = np.array(list(map(int,input().split())))
B = np.array(list(map(int,input().split())))

sum_A = sum(A)
sum_B = sum(B)
if sum_A > K: # 時間を超過する場合
    tmp_cnt = 0
    for i,a in enumerate(A):
        tmp_cnt += a
        if tmp_cnt > K:
            break
    A_n_max = i
else: #時間を超過しない場合
    A_n_max = len(A)
    
cnt = 0
best_cnt = 0
b_start=0
A_t = A[:A_n_max].sum()
B_t = 0
b_j = 0
for a_sub_i in range(A_n_max):
    cnt = A_n_max - a_sub_i
    time_left = K - A_t
   # print(a_sub_i)
   # print(time_left)
    while ((time_left - B_t) > 0) :
        if b_j == len(B):
            b_j += 1
            break
        B_t += B[b_j]
        b_j += 1
            
            
    A_t -= A[A_n_max -1 - a_sub_i]
    cnt = A_n_max - a_sub_i + b_j -1
    if cnt > best_cnt:
        best_cnt = cnt
    
        
print(best_cnt)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from itertools import accumulate
import bisect

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

acum1=[0]
for i in range(n): #累積和ai,bjを求める
    acum1.append(acum1[-1]+arr1[i])
for i in range(m):
    acum2.append(acum2[-1]+arr2[i])

ans = 0
for an in range(n + 1):
    rem = k - acum1[an]
    if rem < 0:
        # aをこれ以上読めません
        break

    bn = bisect.bisect_right(acum2, rem)
    ans = max(ans, an + bn)

print(ans)

Submission status: Runtime Error

Solution code:
from itertools import accumulate
import bisect
 
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
 
acum1=[0]
for i in range(n): #累積和ai,bjを求める
    acum1.append(acum1[-1]+arr1[i])
for i in range(m):
    acum2.append(acum2[-1]+arr2[i])
 
ans = 0
for an in range(n + 1):
    rem = k - acum1[an]
    if rem < 0:
        # aをこれ以上読めません
        break
 
    bn = bisect.bisect_right(acum2, rem)
    ans = max(ans, an + bn)
 
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

while True:
    if len(A) == 0 and len(B) == 0:
        break

    if len(A) == 0 or A[0] >= B[0]:
        min = B.pop(0)
    else:
        min = A.pop(0)
    if K - min < 0:
        break
    K = K - min
    count += 1

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()))
Time=0
ans=0
a=0
b=0
for i in range(N+M+1):
  if A[a]>=B[b]:
    Time+=B[b]
    b+=1
  else:
    Time+=A[a]
    a+=1
  if Time<=K:
    ans+=1
  else:
    break
print(ans)

Submission status: Runtime Error

Solution code:
def sum_from_top(Li):
    rLi = []
    summary = 0
    for i in Li:
        summary += i
        rLi.append(summary)
    return rLi


def ans(a_lists, b_lists, goal):
    cnt = 0
    for i, a_value in enumerate(a_lists):
        evaluate = a_value
        if evaluate > goal:
            break
        cnt = i + 1
    for j, b_value in enumerate(b_lists):
        evaluate = b_value
        if evaluate > goal:
            break
        cnt = max(cnt, j + 1)

    for i, a_value in enumerate(a_lists):
        evaluateA = a_value
        for j, b_value in enumerate(b_lists):
            evaluateB = b_value
            if evaluateA + evaluateB > goal:
                break
            cnt = max(cnt, i + j+2)
    return cnt


deskA_book_cnt, deskB_book_cnt, timeout = map(int, input().split())
deskA_reads = list(map(int, input().split()))
deskB_reads = list(map(int, input().split()))

if timeout < min(deskA_reads[0], deskB_reads[0]):
    print(0)

else:
    from_top_time_A = sum_from_top(deskA_reads)
    from_top_time_B = sum_from_top(deskB_reads)
    max_cnt = ans(from_top_time_A, from_top_time_B, timeout)
print(max_cnt)

Submission status: Runtime Error

Solution code:
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
time = 0
i = 0
j = 0
count = 0
while time <= K:
    if i ==len(A) and j == len(B):
        break
    elif i >= len(A):
        for s in range(j,len(B)):
            time +=B[s]
            if time <= K:
                count +=1
    elif j >= len(B):
        for t in range(i,len(A)):
            time +=B[t]
            if time <=K:
                count += 1
    elif A[i] > B[j]:
        time += B[j]
        j += 1
        if time <= K:
            count += 1
    elif B[j]>=A[i]:
        time += A[i]
        i += 1
        if time <= K:
            count += 1
print(count)