๐ŸŽฒ๋ฐฑ์ค€ 2108๋ฒˆ ํ†ต๊ณ„ํ•™

Jeongeunยท2023๋…„ 2์›” 26์ผ
0

๋ฐฑ์ค€

๋ชฉ๋ก ๋ณด๊ธฐ
22/186

๋ฐฑ์ค€ 2108๋ฒˆ


์ฝ”๋“œ

const fs = require('fs'); 
const input = fs.readFileSync('/dev/stdin').toString().trim().split("\n").map(Number);
const N = input.shift();
const sum = input.reduce((a, b) => a + b, 0);
const result = Math.round(sum / N);
if (result === -0) {
  console.log(0);
} else {
  console.log(result);
}

input.sort((a, b) => a - b);
console.log(input[Math.floor(N / 2)]);

let count = new Array(8001).fill(0);
input.map((item) => count[item + 4000]++);
const max = Math.max(...count);
let indexArr = [];
let index = -1;
do {
  index = count.indexOf(max, index + 1);
  if (index != -1) {
    indexArr.push(index);
  }
} while (index != -1);

if (indexArr.length === 1) {
  console.log(indexArr[0] - 4000);
} else {
  indexArr.sort((a, b) => a - b);
  console.log(indexArr[1] - 4000);
}

console.log(input[N - 1] - input[0]);

0๊ฐœ์˜ ๋Œ“๊ธ€