문제


풀이
효성 X 재영
const solution = (a, b, g, s, w, t) => { const num = g.length; const maxTime = 2 * Math.pow(10, 5); const maxTotal = 2 * Math.pow(10, 9); let start = 0; let end = maxTime * maxTotal; let mid; let answer = 0; while (start <= end) { mid = Math.floor((start + end) / 2); let totalG = 0; let totalS = 0; let add = 0; for (let i = 0; i < num; i += 1) { const nowG = g[i]; const nowS = s[i]; const nowW = w[i]; const nowT = t[i]; let moveCnt = Math.floor(mid / (nowT * 2)); // mid = 1 -> 못 운반하죠? if (mid % (nowT * 2) >= nowT) { moveCnt += 1; } totalG += Math.min(nowW * moveCnt, nowG); totalS += Math.min(nowW * moveCnt, nowS); add += Math.min(nowG + nowS, nowW * moveCnt); } const isPossible = totalG >= a && totalS >= b && add >= a + b; if (isPossible) { end = mid - 1; answer = mid; } else { start = mid + 1; } } return answer; };