Skip to content

Commit 05950b6

Browse files
committed
boj: 1931_회의실 배정 재풀이
1 parent 1ac5c33 commit 05950b6

1 file changed

Lines changed: 22 additions & 3 deletions

File tree

boj/1931_회의실배정.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
const fs = require('fs');
2-
const filePath =
3-
process.platform === 'linux' ? '/dev/stdin' : './boj/input.txt';
2+
const filePath = process.platform === 'linux' ? '/dev/stdin' : 'input.txt';
43
let input = fs.readFileSync(filePath).toString().trim().split('\n');
54

65
let n = Number(input[0].trim());
@@ -28,4 +27,24 @@ function solution(n, work) {
2827
}
2928
return answer;
3029
}
31-
console.log(solution(n, work)); // 4
30+
// console.log(solution(n, work)); // 4
31+
32+
// 2025.04.13
33+
function solution2(n, work) {
34+
const workSorted = work.sort((a, b) => {
35+
if (a[1] === b[1]) return a[0] - b[0];
36+
return a[1] - b[1];
37+
});
38+
39+
let cnt = 1;
40+
let lastTime = workSorted[0][1];
41+
for (let i = 1; i < n; i += 1) {
42+
if (lastTime <= workSorted[i][0]) {
43+
lastTime = workSorted[i][1];
44+
cnt += 1;
45+
}
46+
}
47+
return cnt;
48+
}
49+
50+
console.log(solution2(n, work)); // 4

0 commit comments

Comments
 (0)