We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 5e91e0e commit ad23f85Copy full SHA for ad23f85
1 file changed
live9/test98/문제1/황장현.js
@@ -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