diff --git "a/live8/test86/\353\254\270\354\240\2341/\355\231\251\354\236\245\355\230\204.js" "b/live8/test86/\353\254\270\354\240\2341/\355\231\251\354\236\245\355\230\204.js" new file mode 100644 index 00000000..9ab127f9 --- /dev/null +++ "b/live8/test86/\353\254\270\354\240\2341/\355\231\251\354\236\245\355\230\204.js" @@ -0,0 +1,35 @@ +const input = require('fs') + .readFileSync(process.platform === 'linux' ? '/dev/stdin' : './input.txt') + .toString() + .trim() + .split('\n') + .map((el) => el.split(' ').map(Number)); + +function solution(input) { + const [N, M] = input[0]; + const treeH = input[1].sort((a, b) => a - b); + + let start = 0; + let end = treeH[treeH.length - 1]; + let answer = 0; + + while (start <= end) { + let mid = Math.floor((start + end) / 2); + let sum = 0; + + for (let x of treeH) { + if (x > mid) sum += x - mid; + } + + if (sum >= M) { + answer = mid; + start = mid + 1; + } else { + end = mid - 1; + } + } + + return answer; +} + +console.log(solution(input)); diff --git "a/live8/test86/\353\254\270\354\240\2342/\355\231\251\354\236\245\355\230\204.js" "b/live8/test86/\353\254\270\354\240\2342/\355\231\251\354\236\245\355\230\204.js" new file mode 100644 index 00000000..3c74bc53 --- /dev/null +++ "b/live8/test86/\353\254\270\354\240\2342/\355\231\251\354\236\245\355\230\204.js" @@ -0,0 +1,28 @@ +const input = require('fs') + .readFileSync(process.platform === 'linux' ? '/dev/stdin' : './input.txt') + .toString() + .trim() + .split('\n') + .map((el) => el.split(' ').map(Number)); + +function solution(input) { + const N = input[0][0]; + const 지방예산요청 = input[1].sort((a, b) => a - b); + const M = input[2][0]; + + let high = 지방예산요청[N - 1]; + let low = 0; + + while (low <= high) { + const mid = Math.floor((low + high) / 2); + const sum = 지방예산요청.reduce((acc, v) => acc + (v <= mid ? v : mid), 0); + if (sum > M) { + high = mid - 1; + } else { + low = mid + 1; + } + } + return high; +} + +console.log(solution(input)); diff --git "a/live8/test86/\353\254\270\354\240\2343/\355\231\251\354\236\245\355\230\204.js" "b/live8/test86/\353\254\270\354\240\2343/\355\231\251\354\236\245\355\230\204.js" new file mode 100644 index 00000000..e6d0eacf --- /dev/null +++ "b/live8/test86/\353\254\270\354\240\2343/\355\231\251\354\236\245\355\230\204.js" @@ -0,0 +1,33 @@ +function solution(files) { + let answerWrap = files.map((file, index) => ({ file, index })); + + const compare = (a, b) => { + const reg = /(\D*)([0-9]*)/i; + const A = a.match(reg); + const B = b.match(reg); + + const compareHead = A[1].toLowerCase().localeCompare(B[1].toLowerCase()); + const compareNumber = (a, b) => { + return parseInt(a) > parseInt(b) ? 1 : parseInt(a) < parseInt(b) ? -1 : 0; + }; + return compareHead === 0 ? compareNumber(A[2], B[2]) : compareHead; + }; + + answerWrap.sort((a, b) => { + const result = compare(a.file, b.file); + return result === 0 ? a.index - b.index : result; + }); + + return answerWrap.map((answer) => answer.file); +} + +console.log( + solution([ + 'img12.png', + 'img10.png', + 'img02.png', + 'img1.png', + 'IMG01.GIF', + 'img2.JPG', + ]) +);