Problem: 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.

Submission attempts (in order):
n, m,k = list(map(int, input().split()))
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
count = 0
for i in range(n + m):
    print(k)
    if a_list[0] >= b_list[0] and len(a_list) >= 1:
        k -= a_list.pop(0)
    else:
        k -= b_list.pop(0)
        
    if k > 0:
        count += 1
    else:
        break
        
print(count+1)

n,m,k = list(map(int, input().split()))
a_list = np.array(input().split()).astype(int)
b_list = np.array(input().split()).astype(int)
ans_list=[]
for i in range(n):
    for l in range(m):
        if sum(a_list[:i]) + sum(b_list[:l]) <= k:
            ans_list.append(i+l)
            
ans_list.sort()
print(ans_list[-1])

n, m,k = list(map(int, input().split()))
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
count = 0
for i in range(n + m):
    #print(k)
    if len(a_list) >= 1 and len(b_list) >= 1:
        if a_list[0] >= b_list[0]: 
            k -= a_list.pop(0)
    elif len(a_list) == 0:
        k -= b_list.pop(0)
    else:
        k -= a_list.pop(0)
        
    if k > 0:
        count += 1
    else:
        break
if count == n+m:
    print(count)
else:
    print(count+1)

import numpy as np
param_list = np.array(input().split()).astype(int)
a_list = np.array(input().split()).astype(int)
b_list = np.array(input().split()).astype(int)
ans=0
for i in range(param_list[0]):
    for l in range(param_list[1]):
        a = sum(a_list[:i]) + sum(b_list[:l])
        b= 0
        if  a <= param_list[2]:
            if b <= i+l:
                b = i+l
            
print(b)

import numpy as np
param_list = np.array(input().split()).astype(int)
a_list = np.array(input().split()).astype(int)
b_list = np.array(input().split()).astype(int)
ans=0
for i in range(param_list[0]+1):
    for l in range(param_list[1]+1):
        a = sum(a_list[:i]) + sum(b_list[:l])
        b= 0
        if  a <= param_list[2]:
            if b <= i+l:
                b = i+l
            
print(b)

import numpy as np
n,m,k = list(map(int, input().split()))
a_list = np.array(input().split()).astype(int)
b_list = np.array(input().split()).astype(int)
a_sum =[0]
b_sum=[0]
for i in range(n):
    a_sum.append(a_sum[-1]+ a_list[i])
for i in range(m):
    b_sum.append(b_sum[-1] + b_list[i])
#print(a_sum, b_sum)
total = 0

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

import numpy as np
n,m,k = list(map(int, input().split()))
a_list = np.array(input().split()).astype(int)
b_list = np.array(input().split()).astype(int)
a_sum =[0]
b_sum=[0]
for i in range(n):
    a_sum.append(a_sum[-1]+ a_list[i])
for i in range(m):
    b_sum.append(b_sum[-1] + b_list[i])
#print(a_sum, b_sum)
total = 0
num = m

for i in range(n+1):
    
    if a_sum[i] > k:
        break
    while (k - a_sum[i]) < b_sum[num]:
        num -=1
        #print(i, num)
        if num == -1:
            break
    total = max(i+num, total)
    
    
print(total)

Verdicts: Runtime Error

Runtime Error

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Accepted