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]);

+ Recent posts