<html>
<head>
<meta charset="UTF-8">
<title>4. 졸업선물</title>
</head>
<body>
<script>
function solution(m, product) {
let answer = 0;
let n = product.length;
product = product.sort((a, b) => (a[0] - b[0]));
for (let i = 0; i < n; i++) {
let dc = m - (parseInt(product[i][0] / 2) + product[i][1]);
let cnt = 1, tmp = 0;
for (let j = 0; j < n; j++) {
if (j === i) continue;
else {
tmp += (product[j][0] + product[j][1]);
cnt++
if (tmp >= dc) break;
}
}
answer = Math.max(answer, cnt);
}
return answer;
}
let arr = [[6, 6], [2, 2], [4, 3], [4, 5], [10, 3]];
console.log(solution(28, arr));
</script>
</body>
</html>