// 뮤직비디오(결정알고리즘)
function solution(m, songs) {
let answer = 0;
let max = Math.max(...songs);
while (max) {
let tmp = max;
let cnt = 1;
for (let j = 0; j < songs.length; j++) {
if (tmp - songs[j] < 0) {
tmp = max;
cnt++;
}
tmp -= songs[j];
}
if (cnt === m) {
answer = max;
break;
}
max++;
}
return answer;
}
let arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];
console.log(solution(2, arr));