Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions live8/test86/문제1/황장현.js
Original file line number Diff line number Diff line change
@@ -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));
28 changes: 28 additions & 0 deletions live8/test86/문제2/황장현.js
Original file line number Diff line number Diff line change
@@ -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));
33 changes: 33 additions & 0 deletions live8/test86/문제3/황장현.js
Original file line number Diff line number Diff line change
@@ -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',
])
);