Skip to content

Commit 2abbb3b

Browse files
committed
65차 2번 문제풀이
1 parent 3e495c3 commit 2abbb3b

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

live6/test65/문제2/황장현.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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 = input[0][0];
10+
const schedule = input.slice(1);
11+
const dp = new Array(N).fill(0);
12+
for (let i = 0; i < N; i++) {
13+
const [duration, profit] = schedule[i];
14+
15+
if (i + duration > N) {
16+
continue;
17+
}
18+
dp[i] += profit;
19+
20+
for (let j = i + duration; j < N; j++) {
21+
dp[j] = Math.max(dp[j], dp[i]);
22+
}
23+
}
24+
return Math.max(...dp);
25+
}
26+
27+
console.log(solution(input));

0 commit comments

Comments
 (0)