๐งธ ๋ด๊ฐ ์ฒ์ ์๊ฐํ ์ฝ๋๋ ์๊ฐ์ด๊ณผ๊ฐ ๋ฐ์ํ๋ค.. ์๊ฐ์ ํ์ด ์๋ค๋ฉด ๋ง์์๊น..? ๋ค๋ฅธ ์์ด๋์ด๊ฐ ๋ ์ค๋ฅด์ง ์์ ๊ฒฐ๊ตญ ๋ค๋ฅธ ๋ถ๋ค์ ์ฝ๋๋ฅผ ๋ณด๊ณ ํด๊ฒฐํ๋ค๐ข
์ ๋ต ์ฝ๋
const fs = require('fs');
const input = fs.readFileSync('/dev/stdin').toString().trim().split('\n');
input.shift();
let schedule = [];
input.forEach((item) => {
const [start, end] = item.split(" ").map(Number);
//์์
์์ ์๊ฐ
schedule.push([start, 1]);
//์์
์ข
๋ฃ ์๊ฐ
schedule.push([end, -1]);
});
//์๊ฐ์ ๊ธฐ์ค์ผ๋ก ์ค๋ฆ์ฐจ์์ผ๋ก ์ ๋ ฌ, ์๊ฐ์ด ๊ฐ์ผ๋ฉด ์ข
๋ฃ ์๊ฐ(-1)์ด ์์
schedule.sort((a, b) => (a[0] === b[0] ? a[1] - b[1] : a[0] - b[0]));
let room = 0;
let result = 0;
for (let i = 0; i < schedule.length; i++) {
if (schedule[i][1] === 1) {
//๊ฐ์๊ฐ ์์๋๋ฉด ๋ฐฉ ๊ฐ์ ์ฆ๊ฐ
room++;
} else {
//๊ฐ์๊ฐ ์ข
๋ฃ๋๋ฉด ๋ฐฉ ๊ฐ์ ๊ฐ์
room--;
}
//๋ต์ ์ฌ์ฉํ๋ ๋ฐฉ์ ๊ฐ์๊ฐ ์ต๋๊ฐ ๋ ๋
result = Math.max(room, result);
}
console.log(result)
์๊ฐ์ด๊ณผ ์ฝ๋
const fs = require('fs');
let input = fs.readFileSync('/dev/stdin').toString().trim().split('\n');
const N = +input.shift();
input = input
.map((item) => item.split(" ").map(Number))
.sort((a, b) => a[0] - b[0]);
let room = [input.shift()];
for (let i = 0; i < N - 1; i++) {
//์์ง ๊ฐ์์ค ๋ฐฐ์ ์๋ฐ์ ์์
const [start, end] = input[i];
let isChange = false;
for (let r = 0; r < room.length; r++) {
//๊ฐ์์ค ๋ฐฐ์ ๋ฐ์ ์์
const [rStart, rEnd] = room[r];
if (rEnd <= start) {
room[r] = [start, end];
isChange = true;
break;
}
}
if (!isChange) {
room.push([start, end]);
}
}
console.log(room.length);