-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalgo_4-4.html
32 lines (31 loc) · 1.16 KB
/
algo_4-4.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<html>
<head>
<meta charset="UTF-8">
<title>출력결과</title>
</head>
<body>
<script>
function solution(m, product){
let answer=0;
let n = product.length; // product의 길이
product.sort((a, b) => (a[0] + a[1]) - (b[0] + b[1])); // sort 찾아보고 이해하기
for (let i = 0; i < n; i++) {
let money = m - (product[i][0]/2 + product[i][1]);
let cnt = 1;
for(let j = 0; j < n; j++) {
if (j !== i && (product[j][0] + product[j][1]) > money) {
break;
} if (j !== i && (product[j][0] + product[j][1]) <= money) {
money -= (product[j][0] + product[j][1]);
cnt++;
}
}
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>