Skip to content

Commit db7d425

Browse files
[BOJ] 1535 안녕 (S2)
1 parent e374f87 commit db7d425

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

서정우/8주차/260216.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const fs = require("fs");
2+
const filePath =
3+
process.platform === "linux" ? "/dev/stdin" : "./서정우/input.txt";
4+
const input = fs
5+
.readFileSync(filePath)
6+
.toString()
7+
.trim()
8+
.split("\n")
9+
.map((el) => el.trim());
10+
11+
const N = Number(input[0]);
12+
const lostHealthPerPeople = input[1].split(" ").map(Number);
13+
const earnPleasurePerPeople = input[2].split(" ").map(Number);
14+
15+
const dp = Array(100).fill(0);
16+
17+
for (let i = 0; i < N; i++) {
18+
const L = lostHealthPerPeople[i];
19+
const J = earnPleasurePerPeople[i];
20+
21+
for (let h = 99; h >= L; h--) {
22+
dp[h] = Math.max(dp[h], dp[h - L] + J);
23+
}
24+
}
25+
26+
console.log(Math.max(...dp));

서정우/input.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
999998999
1+
12
2+
1 1 1 1 1 1 1 1 1 1 1 1
3+
100 100 100 100 100 100 100 100 100 100 100 100

0 commit comments

Comments
 (0)