We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
#!/bin/python3importmathimportosimportrandomimportreimportsys## Complete the 'boardCutting' function below.## The function is expected to return an INTEGER.# The function accepts following parameters:# 1. INTEGER_ARRAY cost_y# 2. INTEGER_ARRAY cost_x#defboardCutting(cost_y,cost_x):MOD=10**9+7# Combine the cost arrays and sort themall_costs=sorted([(cost,'h')forcostincost_y]+[(cost,'v')forcostincost_x],reverse=True)# Initialize variableshorizontal_segments=1vertical_segments=1total_cost=0# Process each cut in sorted orderforcost,cut_typeinall_costs:ifcut_type=='h':total_cost=(total_cost+cost*vertical_segments)%MODhorizontal_segments+=1elifcut_type=='v':total_cost=(total_cost+cost*horizontal_segments)%MODvertical_segments+=1returntotal_costif__name__=='__main__':q=int(input().strip())forq_itrinrange(q):first_multiple_input=input().rstrip().split()m=int(first_multiple_input[0])n=int(first_multiple_input[1])cost_y=list(map(int,input().rstrip().split()))cost_x=list(map(int,input().rstrip().split()))result=boardCutting(cost_y,cost_x)print(result)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Cutting Boards
You are viewing a single comment's thread. Return to all comments →