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):
def get_sum_arr(arr):
    sum_arr = [0]
    N = len(arr)
    for i in range(1,N+1):
        sum_arr.append(sum_arr[i-1] + arr[i-1])
    return sum_arr
def get_max_book_num(A,B,K):
    A_sum_arr,B_sum_arr = get_sum_arr(A),get_sum_arr(B)
    count,i,j = 0,0,0
    for i in range(0,len(A_sum_arr)):
        if K < A_sum_arr[i]:
            break
        else:
            print("A:",A_sum_arr[:i])
            j = 0
            while B_sum_arr[j] <= (K - A_sum_arr[i]):
                print("B:",B_sum_arr[:j])
                j += 1
                if j >= len(B_sum_arr):
                    break
            j -= 1
        count = max(count,(i+j))
    return count

if __name__ == "__main__":
    N,M,K = list(map(int,input().split()))
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))
    A_sum_arr,B_sum_arr = get_sum_arr(A),get_sum_arr(B)
    print(get_max_book_num(A,B,K))
    


if __name__ == "__main__":
    N,M,K = list(map(int,input().split()))
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))
    count,i_a,i_b = 0,0,0
    # ADD A item
    for i_a in range(len(A)):
        if K < A[i_a]:
            break
        else:
            count += 1
            K -= A[i_a]
    # replace B item
    
    for i in range((i_a-1),-1,-1):
        K += A[i]
        if i_b >= len(B):
            break
        while True:
            if i_b >= len(B):
                break
            if K < B[i_b] :
                break
            else :
                K -= B[i_b]
                i_b += 1
        count = max(count,((i+1)+(i_b+1)))
    print(count)

if __name__ == "__main__":
    N,M,K = list(map(int,input().split()))
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))
    count,i_a,i_b = 0,0,0
    # ADD A item
    for i_a in range(len(A)):
        if K < A[i_a]:
            i_a -= 1
            break
        else:
            K -= A[i_a]
    # replace B item
    for i_b in range(len(B)):
        if K < B[i_b] :
            i_b -= 1
            break
        else :
            K -= B[i_b]
    
    count = (i_a+1) + (i_b+1) 
    
    
    
    print("{}+{}={}".format(i_a,i_b,count))
    for i in range(i_a,-1,-1): 
        K += A[i] 

        j = 0
        for j in range(i_b+1,len(B)):
            if K < B[j]:
                j -= 1
            else :
                K -= B[j]
        print("i_a:{},i_b:{}".format(i,i_b))
        i_b = j
        
        
        count = max(count,(i+i_b))
    print(count)

if __name__ == "__main__":
    N,M,K = list(map(int,input().split()))
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))
    count,i_a,i_b = 0,0,0
    # ADD A item
    for i_a in range(len(A)):
        if K < A[i_a]:
            i_a -= 1
            break
        else:
            K -= A[i_a]
    # replace B item
    for i_b in range(len(B)):
        if K < B[i_b] :
            i_b -= 1
            break
        else :
            K -= B[i_b]
    
    count = (i_a+1) + (i_b+1) 
    
    
    

    for i in range(i_a,-1,-1): 
        K += A[i]
        for j in range(i_b,len(B)):
            if K < B[i_b]:
                i_b -= 1
            else :
                K -= B[i_b]
        count = max(count,((i)+(i_b+1)))
    print(count)

def get_sum_arr(arr):
    sum_arr = [0]
    N = len(arr)
    for i in range(1,N+1):
        sum_arr.append(sum_arr[i-1] + arr[i-1])
    return sum_arr
def get_max_book_num(A,B,K):
    A_sum_arr,B_sum_arr = get_sum_arr(A),get_sum_arr(B)
    count,i,j = 0,0,0
    for i in range(0,len(A_sum_arr)):
        if K < A_sum_arr[i]:
            break
        else:
            K_temp = K - A_sum_arr[i]
            for j in range(len(B_sum_arr)):
                if B_sum_arr[j] > K_temp:
                    break
                else:
                    K_temp -= B_sum_arr[j]
        count = max(count,(i+j))
    return count

if __name__ == "__main__":
    N,M,K = list(map(int,input().split()))
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))
    A_sum_arr,B_sum_arr = get_sum_arr(A),get_sum_arr(B)
    print(get_max_book_num(A,B,K))
    


if __name__ == "__main__":
    N,M,K = list(map(int,input().split()))
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))
    count,i_a,i_b = 0,0,0
    # ADD A item
    for i_a in range(len(A)):
        if K < A[i_a]:
            i_a -= 1
            break
        else:
            K -= A[i_a]
    # replace B item
    for i_b in range(len(B)):
        if K < B[i_b] :
            i_b -= 1
            break
        else :
            K -= B[i_b]
    
    count = (i_a+1) + (i_b+1) 
    
    
    
    print("{}+{}={}".format(i_a,i_b,count))
    for i in range(i_a,-1,-1): 
        K += A[i] 

        j = 0
        for j in range(i_b+1,len(B)):
            if K < B[j]:
                j -= 1
            else :
                K -= B[j]
        i_b = j + 1
        
        
        count = max(count,(i+i_b))
    print(count)


if __name__=="__main__":
    N,M,K = map(int,input().split())
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))
    A_sum_arr,B_sum_arr = [0],[0]
    for i in range(len(A)):
        A_sum_arr.append(A[i]+A_sum_arr[i])
    for i in range(len(B)):
        B_sum_arr.append(B[i]+B_sum_arr[i])
    count = 0
    j = len(B_sum_arr) - 1
    for i,A_sum in enumerate(A_sum_arr):
        if A_sum > K:
            break
        else:
            b_val = K - A_sum
            while b_val < B_sum_arr[j]:
                j -= 1
            count = max(count,(i+j))
    print(count)

Verdicts: Runtime Error

Wrong Answer

Wrong Answer

Runtime Error

Wrong Answer

Wrong Answer

Accepted