Skip to content

Commit f2a20f7

Browse files
Merge pull request #601 from eric-hjh/main
[황장현] 86차 라이브 코테 제출
2 parents 0ca6ba3 + 18292f3 commit f2a20f7

3 files changed

Lines changed: 96 additions & 0 deletions

File tree

live8/test86/문제1/황장현.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
const input = require('fs')
2+
.readFileSync(process.platform === 'linux' ? '/dev/stdin' : './input.txt')
3+
.toString()
4+
.trim()
5+
.split('\n')
6+
.map((el) => el.split(' ').map(Number));
7+
8+
function solution(input) {
9+
const [N, M] = input[0];
10+
const treeH = input[1].sort((a, b) => a - b);
11+
12+
let start = 0;
13+
let end = treeH[treeH.length - 1];
14+
let answer = 0;
15+
16+
while (start <= end) {
17+
let mid = Math.floor((start + end) / 2);
18+
let sum = 0;
19+
20+
for (let x of treeH) {
21+
if (x > mid) sum += x - mid;
22+
}
23+
24+
if (sum >= M) {
25+
answer = mid;
26+
start = mid + 1;
27+
} else {
28+
end = mid - 1;
29+
}
30+
}
31+
32+
return answer;
33+
}
34+
35+
console.log(solution(input));

live8/test86/문제2/황장현.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const input = require('fs')
2+
.readFileSync(process.platform === 'linux' ? '/dev/stdin' : './input.txt')
3+
.toString()
4+
.trim()
5+
.split('\n')
6+
.map((el) => el.split(' ').map(Number));
7+
8+
function solution(input) {
9+
const N = input[0][0];
10+
const 지방예산요청 = input[1].sort((a, b) => a - b);
11+
const M = input[2][0];
12+
13+
let high = 지방예산요청[N - 1];
14+
let low = 0;
15+
16+
while (low <= high) {
17+
const mid = Math.floor((low + high) / 2);
18+
const sum = 지방예산요청.reduce((acc, v) => acc + (v <= mid ? v : mid), 0);
19+
if (sum > M) {
20+
high = mid - 1;
21+
} else {
22+
low = mid + 1;
23+
}
24+
}
25+
return high;
26+
}
27+
28+
console.log(solution(input));

live8/test86/문제3/황장현.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
function solution(files) {
2+
let answerWrap = files.map((file, index) => ({ file, index }));
3+
4+
const compare = (a, b) => {
5+
const reg = /(\D*)([0-9]*)/i;
6+
const A = a.match(reg);
7+
const B = b.match(reg);
8+
9+
const compareHead = A[1].toLowerCase().localeCompare(B[1].toLowerCase());
10+
const compareNumber = (a, b) => {
11+
return parseInt(a) > parseInt(b) ? 1 : parseInt(a) < parseInt(b) ? -1 : 0;
12+
};
13+
return compareHead === 0 ? compareNumber(A[2], B[2]) : compareHead;
14+
};
15+
16+
answerWrap.sort((a, b) => {
17+
const result = compare(a.file, b.file);
18+
return result === 0 ? a.index - b.index : result;
19+
});
20+
21+
return answerWrap.map((answer) => answer.file);
22+
}
23+
24+
console.log(
25+
solution([
26+
'img12.png',
27+
'img10.png',
28+
'img02.png',
29+
'img1.png',
30+
'IMG01.GIF',
31+
'img2.JPG',
32+
])
33+
);

0 commit comments

Comments
 (0)