Skip to content

Commit 07cb27a

Browse files
committed
114차 2번 문제풀이
1 parent 3a08efa commit 07cb27a

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
const input = require("fs")
2+
.readFileSync(
3+
process.platform === "linux"
4+
? "/dev/stdin"
5+
: require("path").join(__dirname, "input.txt"),
6+
"utf8"
7+
)
8+
.trim()
9+
.split("\n");
10+
11+
function solution(input) {
12+
const N = Number(input[0]);
13+
const circles = [];
14+
15+
for (let i = 1; i <= N; i++) {
16+
const [x, r] = input[i].split(" ").map(Number);
17+
const id = i;
18+
circles.push([x - r, id, 0]);
19+
circles.push([x + r, id, 1]);
20+
}
21+
22+
circles.sort((a, b) => a[0] - b[0]);
23+
24+
const stack = [];
25+
26+
for (const [_, id, type] of circles) {
27+
if (type === 0) {
28+
stack.push([id, type]);
29+
} else {
30+
if (stack.length === 0 || stack[stack.length - 1][0] !== id) {
31+
return "NO";
32+
}
33+
stack.pop();
34+
}
35+
}
36+
37+
return "YES";
38+
}
39+
40+
console.log(solution(input));

0 commit comments

Comments
 (0)