๐งธ ๊ทธ๋๋ ์ด์ ์ด๋ถ ํ์์ ๋ํด ๊ฐ์ด ์กํ ๊ฒ ๊ฐ๋ค!
์ฝ๋
const fs = require('fs');
const input = fs.readFileSync('/dev/stdin').toString().trim().split('\n');
const N = +input.shift();
const request = input
.shift()
.split(" ")
.map(Number)
.sort((a, b) => a - b);
const possible = +input[0];
if (request.reduce((a, b) => a + b, 0) <= possible)
return console.log(Math.max(...request));
let left = 0;
let right = possible;
while (left <= right) {
//์ํ์ก
const mid = Math.floor((left + right) / 2);
let total = 0;
for (el of request) {
if (el <= mid) total += el;
else total += mid;
}
if (total > possible) right = mid - 1;
else left = mid + 1;
}
console.log(right);