Problem:


Score : 300 points

Problem Statement

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

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

Consider the following action:

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

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

Constraints

1 \leq N, M \leq 200000

1 \leq K \leq 10^9

1 \leq A_i, B_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

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

Output

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

Sample Input 1

3 4 240
60 90 120
80 150 80 150

Sample Output 1

3

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

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

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

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

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

Sample Input 2

3 4 730
60 90 120
80 150 80 150

Sample Output 2

7

Sample Input 3

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

Sample Output 3

0

Watch out for integer overflows.



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


Sample output:
3

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from collections import deque

N, M, K = list(map(int, input().split()))
A = deque(map(int, input().split()))
B = deque(map(int, input().split()))
count = 0
while (N != 0 or M != 0):
    if N == 0 and M > 0 and B[0] <= K:
        K -= B[0]
        count += 1
        B.popleft()
        M -= 1
    elif M == 0 and N > 0 and A[0] <= K:
        K -= A[0]
        count += 1
        A.popleft()
        N -= 1
    elif N != 0 and A[0] <= B[0] and A[0] <= K:
        K -= A[0]
        count += 1
        A.popleft()
        N -= 1
    elif M != 0 and B[0] < A[0] and B[0] <= K:
        K -= B[0]
        count += 1
        B.popleft()
        M -= 1
    else:
        break
print(count)

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <algorithm>
#include <vector>


int main()
{
    long long  n,m,k; std::cin >> n >> m >> k;
    // long long  a[n+1], b[m+1];
    std::vector<long long>  a{n+1}, b{m+1};
    a[0]=0; b[0]=0;
    for (int i=1;i<n+1;i++)
        std::cin >> a[i];
    for (int i=1; i<m+1; i++)
        std::cin >> b[i];
    
    for (int i=1; i<n+1; i++)
        a[i]+=a[i-1];
    for (int i=1; i<m+1; i++)
        b[i]+=b[i-1];

    int ans=0, r=m;
    for (int i=0; i<n+1; i++)
    {
        if(a[i]>k) break;
        while (a[i]+b[r]>k)
            r--;
        ans = std::max({ans, i+r});
    }
    
    std::cout << ans;

    return 0;
}

Submission status: Runtime Error

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

sa = [0]*(n+1)
sb = [0]*(m+1)

for i in range(n):
    sa[i+1] = sa[i]+a[i]
for i in range(m):
    sb[i+1] = sb[i]+b[i]

isb=m
ans = 0
for isa in range(n+1):
    if sa[isa]>k:
        break
    while isb>0 and sa[isa]+sb[isb]>K:
        isb-=1
    ans = max(ans, isa+isb)
    
print(ans)

Submission status: Runtime Error

Solution code:
from bisect import bisect_right
from numpy import cumsum
from sys import stdin
input=stdin.readline
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
a=numpy.cumsum(a)
b=numpy.cumsum(b)
ans=0
for i in range(len(a)):
  x=k-a[i]
  y=bisect.bisect_right(b,x)
  if ans<y+i+1:
    ans=y+i+1
print(ans)

Submission status: Runtime Error

Solution code:
from biesect import biesect_right
from numpy import cumsum
from sys import stdin
input=stdin.readline
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
a=numpy.cumsum(a)
b=numpy.cumsum(b)
ans=0
for i in range(len(a)):
  x=k-a[i]
  y=biesect.biesect_right(b,x)
  if ans<y+i+1:
    ans=y+i+1
print(ans)

Submission status: Runtime Error

Solution code:
N, M, K = map(int, input().split())
A = []
B = []
a, *an = map(int, input().split())
A.append(a)
A += an
b, *bn = map(int, input().split())
B.append(b)
B += bn
#print(A)
#print(B)
cost = 0
i = 0
A_cos = []
B_cos = []
f1 = True
f2 = True

while i < len(A) and f1:
    cost += A[i]
    if cost <= K:
        A_cos.append(cost)
    else:
        f1 = False
    i +=1
    
i = 0
cost = 0
while  i < len(B) and f2:
    cost += B[i]
    if cost <= K:
        B_cos.append(cost)
    else:
        f2 = False
    i +=1
    
#print(A_cos)
#print(B_cos)

an = 0
bn = 0
num = 0
j = (len(B_cos)-1)

if len(A_cos) == 0 and len(B_cos) == 0:
    result = 0
elif len(A_cos) == 0:
    result = len(B_cos)
elif len(B_cos) == 0:
    result = len(A_cos)
else:   
    while an < len(A_cos):
        a_cost = A_cos[an]
        while B_cos[j] > K - A_cos[an]:
            j -= 1
        num = max(num, an + j + 2)       
        an += 1
    result = num    
print(result)

Submission status: Runtime Error

Solution code:
n,m,k=map(int,raw_input().split())
a=map(int,raw_input().split())
b=map(int,raw_input().split())
cnt1=0
cnt2=0
a1=[0]
b1=[0]
for i in range(n):
    a1.append(a1[-1]+a[i])
for i in range(m):
    b1.append(b1[-1]+b[i])
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)
print ans

Submission status: Runtime Error

Solution code:
n,m,k=map(int,raw_input().split())
a=map(int,raw_input().split())
b=map(int,raw_input().split())
cnt1=0
cnt2=0
a1=[0]
b1=[0]
for i in range(n):
    a1.append(a1[-1]+a[i])
for i in range(n):
    b1.append(b1[-1]+b[i])
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)
print ans

Submission status: Runtime Error

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


a = [int(e) for e in input().split()]
b = [int(e) for e in input().split()]
 
time = 0
satsu = 0
an = 0
bn = 0

while time < k:
    
    if a[an] >= b[bn]:
        time += b[bn]
        bn = bn+1
        satsu = satsu + 1
        
        
            
            
    
    elif b[bn] >= a[an]:
        time += a[bn]
        an = an+1
        satsu = satsu + 1
        
        
 
print(satsu-1)

Submission status: Runtime Error

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

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

time = 0
satsu = 0

while time < k:
    an = 0
    bn = 0
    if a[an] >= b[bn]:
        time += b[bn]
        bn = bn+1
        satsu = satsu + 1
        
        for o in range(n-2):
            b[o] = b[o+1]
            
            
    
    elif b[bn] >= a[an]:
        time += a[bn]
        an = an+1
        satsu = satsu + 1
        
        for l in range(m-2):
            a[l] = a[l+1]
            

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

Asum_li = [0]
Asum = 0
Bsum_li = [0]
Bsum = 0

for A_ in A:
    Asum = Asum + A_
    Asum_li.append(Asum)

for B_ in B:
    Bsum = Bsum + B_
    Bsum_li.append(Bsum)

cnt_max = 0
cnt_b = M

for cnt_a in range(N+1):

    while (Bsum_li[cnt_b] + Asum_li[cnt_a]) > K:
        cnt_b = cnt_b - 1
        if cnt_b < 0: break

    if (cnt_max < cnt_b + cnt_a): cnt_max = cnt_b + cnt_a


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

b_li = [0]
b_ = 0

for B_ in B:
    b_ = b_ + B_
    b_li.append(b_)

book_max = 0
book_cnt_a = 0
book_cnt_ab = 0
a_ = 0
book_cnt_ab = M

for i in range(N+1):
    while (b_li[book_cnt_ab-1] + a_) > K:
        book_cnt_ab = book_cnt_ab - 1
        if book_cnt_ab == 0: break
    if (book_max <= book_cnt_ab + book_cnt_a):
            book_max = book_cnt_ab + book_cnt_a
    book_cnt_a = book_cnt_a + 1
    if i >= N: break
    a_ = a_ + A[i]

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

b_li = [0]
b_ = 0

for B_ in B:
    b_ = b_ + B_
    b_li.append(b_)

book_max = 0
book_cnt_a = 0
book_cnt_ab = 0
a_ = 0
book_cnt_ab = M

for i in range(N+1):
    while (b_li[book_cnt_ab-1] + a_) > K:
        book_cnt_ab = book_cnt_ab - 1
    if (book_max <= book_cnt_ab + book_cnt_a):
            book_max = book_cnt_ab + book_cnt_a
    book_cnt_a = book_cnt_a + 1
    if i >= N: break
    a_ = a_ + A[i]

print(book_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_li = [0]
a_ = 0
b_li = [0]
b_ = 0

for A_ in A:
    a_ = a_ + A_
    a_li.append(a_)

for B_ in B:
    b_ = b_ + B_
    b_li.append(b_)

book_max = 0
book_cnt_a = 0
book_cnt_ab = 0

for a_ in a_li:
    book_cnt_ab = M
    for b_ in b_li.reverse():
        if (a_ + b_) < K:
            if (book_max <= book_cnt_ab + book_cnt_a):
                book_max = book_cnt_ab + book_cnt_a
            break
        book_cnt_ab = book_cnt_ab - 1
    book_cnt_a = book_cnt_a + 1

print(book_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()))
T, i, j, books = 0

while K < T:
    if A[i] < B[j]:
        T = A[i]
        i += 1
    else:
        T = B[j]
        i += 1
    books += 1
    
prin(books)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

acum1 = [0]
for i in range(n):
    acum1.append(acum1[-1] + a[i])

acum2 = [0]
for i in range(m):
    acum2.append(acum2[-1]+b[i])
i = 0
ans = 0
j = m
while acum1[i]<=k:
    while acum2[j]>k-acum1[i] and j>0:
        j -= 1
    ans = max(ans,i+j)
    i+=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()))

acum1 = [0]
for i in range(n):
    acum1.append(acum1[-1] + a[i])

acum2 = [0]
for i in range(m):
    acum2.append(acum2[-1]+b[i])
i = 0
ans = 0
j = m
while acum1[i]<k:
    while acum2[j]>k-acum1[i] and j>0:
        j -= 1
    ans = max(ans,i+j)
    i+=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()))

acum1 = [0]
for i in range(n):
    acum1.append(acum1[-1] + a[i])

acum2 = [0]
for i in range(m):
    acum2.append(acum2[-1]+b[i])
i = 0
ans = 0
while acum1[i]<k:
    j = m
    while acum2[j]>k-acum1[i] and j>0:
        j -= 1
    ans = max(ans,i+j)
    i+=1
print(ans)

Submission status: Runtime Error

Solution code:
def strToList(str,offset=0):
    res = [];
    for el in str.split(" "):
        if el!='':
            res.append(int(el)+offset)
    return res


[N,M,K] = strToList(input())
A = strToList(input())
B = strToList(input())

current_time = 0
current_value = 0
iA = 0
iB = 0

while iA<N:
    if current_time+A[iA]<=K:
        current_time+=A[iA]
        current_value+=1
        iA+=1
    else:
        break

max_value = current_value

while iA>=0 and iB<M:
    if current_time+B[iB]<=K:
        current_time+=B[iB]
        iB+=1
        current_value+=1
        if current_value>max_value:
            max_value=current_value
    else:
        current_time-=A[iA]
        iA-=1
        current_value-=1

print(max_value)

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()))
    import itertools
    zero = [0]
    sum_a = zero + list(itertools.accumulate(a))
    sum_b = zero + list(itertools.accumulate(b))

    if sum_a[-1] + sum_b[-1] <= k:
        print(n+m)
        return
    if a[1] > k and b[1] > k:
        print(0)
        return

    for i in range(n+1):
        if sum_a[i] > k:
            break
    start_a = i - 1

    for i in range(m+1):
        if sum_b[i] + sum_a[start_a] > k:
            break
    start_b = i - 1

    ans = start_a + start_b
    for a_i in range(start_a-1, -1, -1):
        for b_i in range(start_b, m+1):
            now_sum_time = sum_a[a_i] + sum_b[b_i]
            if now_sum_time > k:
                cnt_b = b_i - 1
                break
            if b_i == m:
                cnt_b = b_i
        ans = max(ans, a_i + cnt_b)
    print(ans)
if __name__=='__main__':
    main()

Submission status: Runtime Error

Solution code:
# abc172_c.py
# https://atcoder.jp/contests/abc172/tasks/abc172_c

# C - Tsundoku /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 300点

# 問題文
# 二台の机 A, B があります。机 A には N冊の本が、机 B には M冊の本が、それぞれ縦に積まれています。
# 机 A に現在上から i番目に積まれている本 (1≤i≤N) は読むのに Ai 分を要し、
# 机 B に現在上から i 番目に積まれている本 (1≤i≤M) は読むのに Bi分を要します。

# 次の行為を考えます。
#     本が残っている机を選び、その机の最も上に積まれた本を読んで机から取り除く。
#     合計所要時間が K分を超えないようにこの行為を繰り返すとき、最大で何冊の本を読むことができるでしょうか。
#     本を読むこと以外に要する時間は無視します。

# 制約
#     1≤N,M≤200000
#     1≤K≤109
#     1≤Ai,Bi≤109
#     入力中の値はすべて整数である。

# 入力
# 入力は以下の形式で標準入力から与えられる。

# N M K
# A1 A2 … AN
# B1 B2 … BM

# 出力
# 読むことのできる本の最大数を表す整数を出力せよ。

# 入力例 1
# 3 4 240
# 60 90 120
# 80 150 80 150

# 出力例 1
# 3

# この場合、机 A の上から 1,2,3番目の本はそれぞれ読むのに 60 分、90 分、120 分を要し、
# 机 B の上から 1,2,3,4 番目の本はそれぞれ読むのに 80 分、150 分、80 分、150分を要します。

# 以下のようにすることで 230分で 3 冊の本を読むことができ、これが 240分以内に読むことのできる本の最大数です。

#     机 A の最も上に積まれている本を 60分かけて読み、この本を机から取り除く。
#     机 B の最も上に積まれている本を 80分かけて読み、この本を机から取り除く。
#     机 A の最も上に積まれている本を 90分かけて読み、この本を机から取り除く。

# 入力例 2
# 3 4 730
# 60 90 120
# 80 150 80 150

# 出力例 2
# 7

# 入力例 3
# 5 4 1
# 1000000000 1000000000 1000000000 1000000000 1000000000
# 1000000000 1000000000 1000000000 1000000000

# 出力例 3
# 0

# 整数のオーバーフローに注意してください。


def calculation(lines):
    import numpy as np
    N, M, K = map(int, lines[0].split(' '))
    A = map(int, lines[1].split(' '))
    A = [value for value in A]
    B = map(int, lines[2].split(' '))
    B = [value for value in B]
    result = 0
    max_total = 0
    sum_a = list()
    sum_a.append(0)
    sum_b = list()
    sum_b.append(0)
    # for a in range(N):
    #     if a == 0:
    #         sum_a.append(A[a])
    #     else:
    #         sum_a.append(A[a] + sum_a[a-1])
    # print(f'sum_a=[{sum_a}]')
    # print(f'A=[{A}]')
    sum_a = np.cumsum(sum_a.extend(A))
    # print(f'sum_a=[{sum_a}]')
    # for b in range(M):
    #     if b == 0:
    #         sum_b.append(B[b])
    #     else:
    #         sum_b.append(B[b] + sum_b[b-1])
    # print(f'sum_b=[{sum_b}]')
    sum_b = np.cumsum(np.array(sum_b.extend(B)))
    for a in range(len(sum_a)):
        for b in range(len(sum_b)):
            if sum_a[a] + sum_b[b] > K:
                break
            if a+b > result:
                # print(str(a) + ',' + str(b))
                result = a+b
    return [result]


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['3 4 240', '60 90 120', '80 150 80 150']
        lines_export = [3]
    if pattern == 2:
        lines_input = ['3 4 730', '60 90 120', '80 150 80 150']
        lines_export = [7]
    if pattern == 3:
        lines_input = ['5 4 1', '1000000000 1000000000 1000000000 1000000000 1000000000', '1000000000 1000000000 1000000000 1000000000']
        lines_export = [0]
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    if len(args) == 1:
        mode = 0
    else:
        mode = int(args[1])
    return mode


# 主処理
def main():
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(3)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')


# 起動処理
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
n, m, k = map(int, input().split(" "))

a = list(map(int, input().split(" ")))
b = list(map(int, input().split(" ")))

for i in range(1, n):
    a[i] += a[i - 1]
for i in range(1, m):
    b[i] += b[i - 1]

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

Submission status: Runtime Error

Solution code:
def easy_Greedy():
    NMK=input().split(" ")
    N,M,K=int(NMK[0]),int(NMK[1]),int(NMK[2])
    A=input().split(" ")
    A=[int(i) for i in A]
    B=input().split(" ")
    B=[int(i) for i in B]
    time=0
    book=0
    while(True):
        mintime=min(A[0],B[0])
        if K-time<mintime:
            break
        else:
            time+=mintime
            if mintime=A[0]:
                A=A[1:]
            else:
                B=B[1:]
            book+=1
    print(book)

if __name__ == "__main__":
    easy_Greedy()

Submission status: Runtime Error

Solution code:
[N,M,K]=list(map(int,input().split()))
L_A=list(map(int,input().split()))
L_B=list(map(int,input().split()))
S_A = []
S_B = []
S = 0
for i in range(N):
    if S + L_A[i] <= K:
        S += L_A[i]
        S_A.append(S)
    else:
        break
S = 0
for i in range(M):
    if S + L_B[i] <= K:
        S += L_B[i]
        S_B.append(S)
    else:
        break
a = len(S_A)
b = len(S_B)
if a * b == 0:
    print(a+b)
elif S_A[-1] + S_B[-1] <= K:
    print(a+b)
else:
    ans = a
    for i in range(b):
        if S_A[-1] + S_B[i] > K:
            ans += i
            break
    for j in range(a-1,-1,-1):
        if j + b + 1 <= ans:
            break
        if S_A[j] + S_B[ans-j-1] <= K:
            k = ans-j-1
            for x in range(k,b+1,1):
                if S_A[j] + S_B[x] > K:
                    ans = j + x + 2
                    break
    print(ans)

Submission status: Runtime Error

Solution code:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ruia=[0]
ruib=[0]
mx=0
for (i,j) in zip(a,range(n)):
  ruia.append(ruia[j]+i)

for (i,j) in zip(b,range(m)):
  ruib.append(ruib[j]+i)

for i in range(n+1,-1,-1):
  ans=-1
  if ruia[i]>k:
    continue
  for j in range(mx,m):
    if rui[i]+rui[j]>k:
      ans=i+j-1
      break
  else:
    ans=i+m
  if ans>mx:
    mx=ans
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()))

newa = [0]*n
newb = [0]*m

for i in range(n):
    newa[i] = sum(a[0:i+1])
for j in range(m):
    newb[j] = sum(b[0:j+1])

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

print(ans)

Submission status: Runtime Error

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

  # nは入力回数
A = list(map(int, input().split()))

B = list(map(int, input().split()))
sum=0
count = 0
for i in range(N+M):
    if A[0] >= B[0]:
        temp = B.pop(0)
        if sum+int(temp) > K:
            break
            print(count)
        else:
            sum +=temp
            count += 1

    else:
        temp = A.pop(0)
        if sum + int(temp) > K:
            break
            print(count)
        else:
            sum += temp
            count += 1

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

summ, count = 0, 0
i, j = 0, 0
while summ < k and (i <= n-1 or j <= m-1):
    if i <= n-1 and a[i] <= b[j]:
        if summ + a[i] <= k:
            summ += a[i]
            i += 1
            count += 1
        else: break
    elif j <= m-1:
        if summ+b[j] <= k:
            summ += b[j]
            j += 1
            count += 1
        else: break
print(count)

Submission status: Runtime Error

Solution code:
N,M,K = map(int, input().split())
  # nは入力回数
A = [list(map(int, input().split())) for _ in range(N)]

B = [list(map(int, input().split())) for _ in range(M)]

sum=0
count = 0
for i in range(N+M):
    if A[0] >= B[0]:
        temp = B.pop(0)
        if sum+temp > K:
            break
            print(count)
        else:
            sum +=temp
            count += 1

    else:
        temp = A.pop(0)
        if sum + temp > K:
            break
            print(count)
        else:
            sum += temp
            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()))
ta=sum(a)
a.append(0)
tb=0
ans=0
j=0
for i in range(n+1):
    ta -= a[n-i]
    if ta>k:
        continue
    while tb + ta<k:

        if j ==n:
            ans=max(ans,n-i+j+1)
            break
        tb += b[j]
        ans=max(ans,n-i+j)
        j +=1

print(ans)

Submission status: Runtime Error

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

a, b = [0], [0]
for i in range(N):
    a.append(a[i] + A[i])
for i in range(M):
    b.append(b[i] + B[i])

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

Submission status: Runtime Error

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

sumA = []
sumB = []
tmp = 0
answer = 0
st = 1

for i in range(N):
    tmp = tmp + A[i]
    sumA.append(tmp)

tmp = 0
for i in range(M):
    tmp = tmp + B[i]
    sumB.append(tmp)

for i in range(N, 0, -1):
    booktmp = 0

    for j in range(st , M + 1):

        if sumA[i-1] + sumB[j-1] <= K:
            booktmp = i + j
            st = st + 1
        else:
            st = st - 1
            break
    answer = max(answer, booktmp)


print(answer)

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!

def main():
    num_book_table_a,num_book_table_b,time_limit = map(int,input().split())
    tables_a = list(map(int,input().split())) ; tables_b = list(map(int,input().split()))
    
    result = 0
    values = 0
    while True:
        if tables_a[0] <= tables_b[0]:
            comp = tables_a.pop(0)
        else:
            comp = tables_b.pop(0)
        
        result += 1
        values += comp
        
        if values > time_limit:
            result -= 1
            break
    
    print(result)
           
if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
if k >= sum(a) + sum(b):
    print(n + m)
    exit()
ans = -1
total_time = 0
a_cnt = 0
b_cnt = 0
while total_time <= k:
    read_time = min(a[a_cnt], b[b_cnt])
    if read_time == a[a_cnt]:
        if a_cnt < len(a) - 1:
            a_cnt += 1
        else:
            b_cnt += 1
    else:
        if b_cnt < len(b) - 1:
            b_cnt += 1
        else:
            a_cnt += 1
    total_time += read_time
    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()))
if k >= sum(a) + sum(b):
    print(n + m)
    exit()
ans = -1
total_time = 0
a_cnt = 0
b_cnt = 0
while total_time <= k:
    read_time = min(a[a_cnt], b[b_cnt])
    if read_time == a[a_cnt]:
        if a_cnt < len(a):
            a_cnt += 1
        else:
            b_cnt += 1
    else:
        if b_cnt < len(b):
            b_cnt += 1
        else:
            a_cnt += 1
    total_time += read_time
    ans += 1

print(ans)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

N, M, K = map(int, input().split())
result = 0 # max
a_time = list(map(int, input().split()))
b_time = list(map(int, input().split()))

sum = 0

a_num = 0
for i in range(N):
    sum += a_time[i]
    a_num += 1
    if sum > K:
        sum -= a_time[i]
        a_num -= 1
        break
i = a_num
while i >= 0:
    sum -= a_time[i]
    for j in range(M):
        sum += b_time[j]
        if sum > K:
            sum -= b_time[j]
            break
    if result < i + j:
        result = i + j
    i -= 1

print(result)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

N, M, K = map(int, input().split())
result = 0 # max
a_time = list(map(int, input().split()))
b_time = list(map(int, input().split()))

sum = 0

a_num = 0
for i in range(N):
    sum += a_time[i]
    a_num += 1
    if sum > K:
        sum -= a_time[i]
        a_num -= 1
        break
i = a_num
while i >= 0:
    sum -= a_time[i]
    for j in range(M):
        sum += b_time[j]
        if sum > K:
            sum -= b_time[j]
            break
    print('result={} i={} j={}'.format(result, i, j))
    if result < i + j:
        result = i + j
    i -= 1

print(result)

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:
n, m, k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

total = 0
count = 0
flag = len(a) - 1
for i in range(n):
    total += a[i]
    if total > k:
        total -= a[i]
        flag = i
        break
    count += 1
ans = count
for i in range(m):
    if b[i] > k:
        break
    total += b[i]
    count += 1
    while total > k:
        total -= a[flag]
        flag -= 1
        count -= 1
    ans = max(ans, count)

print(ans)

Submission status: Runtime Error

Solution code:
n, m, k = map(int, input().split())
alst = list(map(int, input().split()))
blst = list(map(int, input().split()))
alst.append(2*10**9)
blst.append(2*10**9)
ptime = 0
acou = 0
bcou = 0
books = 0
while True:
    if alst[acou] < blst[bcou]:
        ptime += alst[acou]
        acou += 1
    elif alst[acou] > blst[bcou]:
        ptime += blst[bcou]
        bcou += 1
    else:
        if alst[acou+1] < blst[bcou+1]:
            ptime += alst[acou]
            acou += 1
        elif alst[acou+1] > blst[bcou+1]:
            ptime += blst[bcou]
            bcou += 1
    if ptime <= k:
        books += 1
    elif acou==len(alst)-1 and bcou==len(blst)-1:
        books += 1
        break
    else:
        break
print(books)

Submission status: Runtime Error

Solution code:
n, m, k = map(int, input())
a_books = map(int, input().split())
b_books = map(int, input().split())

result = 0
while k > 0:
  if a_books and b_books:
    if a_books[0] <= b_books[0]:
      time = a_books.pop(0)
    else:
      time = b_books.pop(0)
  elif a_books and not b_books:
    time = a_books.pop(0)
  elif not a_books and b_books:
    time = b_books.pop(0)
  else:
    break
  
  if time <= k:
    result += 1
    k -= time

print(result)

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

totalA = [0]
totalB = [0]
sumA = 0
for i in range(N):
    sumA += A[0]
    totalA.append(sumA)
sumB = 0
for i in range(M):
    sumB += B[0]
    totalB.append(sumB)

iA = N
iB = 0
countMax = 0
while iA >= 0:
    if totalA[iA] + totalB[iB] > K:
        iA -= 1
    else:
        if iB < M:
            countMax = max(countMax, iA + iB)
            iB += 1
    elif iA == N and iB == M:
        countMax = max(countMax, iA + iB)
        break

print(countMax)

Submission status: Runtime Error

Solution code:
def checkWhichToRead(A, B):
    if len(A) == 0 or A[0] > B[0]:
        return 1
    elif len(B) == 0 or A[0] < B[0]:
        return 0
    else:
        return 2


def searchEqualCase(A, B, K, count):
    if K < 0:
        return count
    ACount = count
    BCount = count
    if len(A) > 0:
        ACount = searchEqualCase(A[1:], B, K - A[0], count + 1)
    if len(B) > 0:
        BCount = searchEqualCase(A, B[1:], K - B[0], count + 1)
    if ACount > BCount:
        return ACount
    else:
        return BCount


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

count = 0
while K >= 0:
    case = checkWhichToRead(A, B)
    if case == 0:
        K -= A[0]
        A = A[1:]
    elif case == 1:
        K -= B[0]
        B = B[1:]
    else:
        count = searchEqualCase(A, B, K, count)
        break
    count += 1
    if count == N + M:
        count += 1
        break

print(count - 1)

Submission status: Runtime Error

Solution code:
def checkWhichToRead(A, B):
    if len(A) == 0 or A[0] > B[0]:
        return 1
    elif len(B) == 0 or A[0] < B[0]:
        return 0
    else:
        return 2


def searchEqualCase(A, B, K, count):
    if K < 0:
        return count
    ACount = count
    BCount = count
    if len(A) > 0:
        ACount = checkWhichToRead(A[1:], B, K - A[0], count + 1)
    if len(B) > 0:
        BCount = checkWhichToRead(A, B[1:], K - B[0], count + 1)
    if ACount > BCount:
        return ACount
    else:
        return BCount


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

count = 0
while K >= 0:
    case = checkWhichToRead(A, B)
    if case == 0:
        K -= A[0]
        A = A[1:]
    elif case == 1:
        K -= B[0]
        B = B[1:]
    else:
        count = searchEqualCase(A, B, K, count)
        break
    count += 1
    if count == N + M:
        count += 1
        break

print(count - 1)