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.
medium problem I guess, just based on sorting actually
defboardCutting(cost_y,cost_x):#cost_y ... 0 to m-2, cost_x ... 0 to n-2rows=len(cost_y)+1cols=len(cost_x)+1hs=1#horizontalsegmentsvs=1#verticalsegmentscost_x.sort(reverse=True)cost_y.sort(reverse=True)sum=0while(len(cost_x)andlen(cost_y)):if(cost_y[0]>cost_x[0]):m=cost_y.pop(0)vsf=1#verticalsegmentflaghsf=0else:m=cost_x.pop(0)vsf=0hsf=1if(vsf):sum+=(m*vs)hs+=1if(hsf):sum+=(m*hs)vs+=1while(len(cost_x)):m=cost_x.pop(0)sum+=(m*hs)vs+=1#noneedwhile(len(cost_y)):m=cost_y.pop(0)sum+=(m*vs)hs+=1returnsum%1000000007
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 →
medium problem I guess, just based on sorting actually