728x90
const fs = require('fs');
const input = fs.readFileSync("/dev/stdin").toString().trim().split("\n");
const [N, M] = input[0].split(" ").map(Number);
let arr = input[1].split(" ").map(Number);
arr = arr.sort((a, b) => a-b)
let result = 0;
let sum = 0;
for (let i = 0; i < N; i++) {
for (let j = i+1; j < N; j++) {
for (let k = j+1; k < N; k++) {
sum = arr[i] + arr[j] + arr[k];
if(M-sum >=0 && result <= sum) {
result = sum
}
}
}
}
console.log(result)
728x90
'Development > 코딩테스트' 카테고리의 다른 글
[백준] 1181 Node.js (0) | 2022.10.26 |
---|---|
[백준] Node.js 2775 (0) | 2022.10.12 |
[백준] 2292 Node.js (0) | 2022.09.29 |
[백준] 1085 Node.js (0) | 2022.09.29 |
[백준] 1259 Node.js (0) | 2022.09.28 |
댓글