You are viewing a single comment's thread. Return to all comments →
js
function boardCutting(cost_y, cost_x) { const M = (10**9) + 7 let cuts = cost_y.length + cost_x.length let cost = 0, H = 1, V = 1 cost_y.sort((a, b) => a-b), cost_x.sort((a, b) => a-b) let costH = cost_y.pop(), costV = cost_x.pop() while (cuts) { if (costH > costV) { H++ cost += costH * V costH = cost_y.pop() ?? 0 } else { V++ cost += costV * H costV = cost_x.pop() ?? 0 } cost = cost % M, cuts-- } return cost }
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 →
js