Skip to content

Commit ad23f85

Browse files
author
Eric
committed
98차 1번 문제풀이
1 parent 5e91e0e commit ad23f85

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

live9/test98/문제1/황장현.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
const input = require('fs')
2+
.readFileSync(process.platform === 'linux' ? '/dev/stdin' : './input.txt')
3+
.toString()
4+
.trim()
5+
.split('\n')
6+
.map((el) => el.split(' ').map(Number));
7+
8+
function solution(input) {
9+
const [N, M] = input[0];
10+
const numArr = [0, ...input[1]];
11+
12+
function bF(idx, sec, size) {
13+
if (sec > M) return 0;
14+
if (sec === M || idx >= N) return size;
15+
16+
let ans = 0;
17+
ans = Math.max(
18+
idx + 1 <= N ? bF(idx + 1, sec + 1, size + numArr[idx + 1]) : 0,
19+
idx + 2 <= N
20+
? bF(idx + 2, sec + 1, Math.floor(size / 2) + numArr[idx + 2])
21+
: 0
22+
);
23+
24+
return ans;
25+
}
26+
27+
return bF(0, 0, 1);
28+
}
29+
30+
console.log(solution(input));

0 commit comments

Comments
 (0)