From b5604ccb78b466732eec2aaed4f963bc7d94433c Mon Sep 17 00:00:00 2001 From: Eric Date: Fri, 28 Feb 2025 11:10:19 +0900 Subject: [PATCH 1/4] =?UTF-8?q?86=EC=B0=A8=201=EB=B2=88=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C=ED=92=80=EC=9D=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\355\231\251\354\236\245\355\230\204.js" | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 "live8/test86/\353\254\270\354\240\2341/\355\231\251\354\236\245\355\230\204.js" 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)); From a600ced6ecdd567d273f9d2210c119a071ece0a6 Mon Sep 17 00:00:00 2001 From: Eric Date: Fri, 28 Feb 2025 11:10:25 +0900 Subject: [PATCH 2/4] =?UTF-8?q?86=EC=B0=A8=202=EB=B2=88=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C=ED=92=80=EC=9D=B4(=ED=91=B8=EB=8A=94=EC=A4=91)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\355\231\251\354\236\245\355\230\204.js" | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 "live8/test86/\353\254\270\354\240\2342/\355\231\251\354\236\245\355\230\204.js" 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..597bbb9c --- /dev/null +++ "b/live8/test86/\353\254\270\354\240\2342/\355\231\251\354\236\245\355\230\204.js" @@ -0,0 +1,22 @@ +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); + } +} + +console.log(solution(input)); From b12fe774d71e4a5ea1f08bd067c062dccf8df10b Mon Sep 17 00:00:00 2001 From: Eric Date: Mon, 3 Mar 2025 20:52:23 +0900 Subject: [PATCH 3/4] =?UTF-8?q?86=EC=B0=A8=202=EB=B2=88=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C=ED=92=80=EC=9D=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\355\231\251\354\236\245\355\230\204.js" | 6 ++++++ 1 file changed, 6 insertions(+) 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" index 597bbb9c..3c74bc53 100644 --- "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" @@ -16,7 +16,13 @@ function solution(input) { 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)); From 18292f35d20c29c6e63310f9eca2cd9ee9615ea0 Mon Sep 17 00:00:00 2001 From: Eric Date: Mon, 3 Mar 2025 20:52:29 +0900 Subject: [PATCH 4/4] =?UTF-8?q?86=EC=B0=A8=203=EB=B2=88=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C=ED=92=80=EC=9D=B4(=EC=B0=B8=EA=B3=A0)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\355\231\251\354\236\245\355\230\204.js" | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 "live8/test86/\353\254\270\354\240\2343/\355\231\251\354\236\245\355\230\204.js" 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', + ]) +);