https://www.acmicpc.net/problem/2798
const fs=require('fs');
const filepath=process.platform==='linux'?'dev/stdin':'./input.txt';
let input=fs.readFileSync(filepath).toString().split("\n");
input[0]=input[0].split(" ").map(ele=>+(ele));
const n=input[0][0];
const target=input[0][1];
const arr=input[1].split(" ").map(ele=>+(ele));
let elements=new Array(3);
// console.log(elements);
console.log(solution(0, elements, 0));
function solution(depth, elements, start){
if(depth==3){
let result=0;
for(let i=0;i<3;++i){
result+=elements[i];
}
return result;
}
let answer=0;
for(let i=start;i<arr.length;++i){
elements[depth]=arr[i];
let result=solution(depth+1, elements, i+1);
if(result<=target &&result>answer)answer=result;
}
return answer;
}
'FrontEnd > PS through Javascript' 카테고리의 다른 글
Node.js) BOJ 11286번 : 절댓값 힙 (0) | 2024.02.04 |
---|---|
백준(BOJ) 1463: 1로 만들기 (1) | 2024.02.03 |
백준(BOJ) 2920: 음계 (0) | 2024.01.22 |
백준(BOJ) 4344: 평균은 넘겠지 (0) | 2024.01.22 |
자바스크립트에서 값 입력받기 (0) | 2024.01.22 |