https://www.acmicpc.net/problem/2217
이 문제는 그리디
문제이다.
로프가 1개일 때부터 N개일 때 까지의 최대 중량을 계산하면 된다.
const fs = require("fs");
const [N, ...rope] = (
process.platform === "linux"
? fs.readFileSync("/dev/stdin").toString().trim()
: `5
27
23
15
11
3`
)
.split("\n")
.map(Number);
rope.sort((a, b) => b - a);
let maxWeight = [];
for (let i = 0; i < N; i++) {
maxWeight.push(rope[i] * (i + 1));
}
console.log(Math.max.apply(null, maxWeight));
그리디 문제에 겁부터 먹고 풀었더니 풀이가 계속 꼬였다. 두번이나 틀렸달까..?ㅠㅠ
하나씩 차근차근 생각해보면 쉽게 풀릴 것을.. 한참을 풀었다. silver4문제인데ㅠㅠ 이번주는 그리디를 집중적으로 풀 예정이기 때문에 내일부터는 차분히 생각하고 로직을 그리고 풀어야 겠다.😎