Javascript

[백준 알고리즘] javascript 로프 2217번

호박고구마123 2024. 2. 28. 00:18
const filePath = process.platform === "linux" ? "/dev/stdin" : "ex.txt";
const [N, ...ropes] = require("fs")
  .readFileSync(filePath)
  .toString()
  .trim()
  .split("\n")
  .map((item) => parseInt(item));

ropes.sort((a, b) => a - b);
let maxWeights = [];
for (let i = N; i >= 1; --i) {
  maxWeights.push(i * ropes[N - i]);
}

maxWeights.sort((a, b) => b - a);
console.log(maxWeights[0]);