We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 6b29244 commit e1d98adCopy full SHA for e1d98ad
1 file changed
live12/test123/문제2/황장현.js
@@ -0,0 +1,29 @@
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
+const N = input[0][0];
9
+const lines = input.slice(1).sort((a, b) => a[0] - b[0]);
10
11
+let totalLength = 0;
12
+let currentStart = lines[0][0];
13
+let currentEnd = lines[0][1];
14
15
+for (let i = 1; i < N; i++) {
16
+ const [start, end] = lines[i];
17
18
+ if (start <= currentEnd) {
19
+ currentEnd = Math.max(currentEnd, end);
20
+ } else {
21
+ totalLength += currentEnd - currentStart;
22
+ currentStart = start;
23
+ currentEnd = end;
24
+ }
25
+}
26
27
+totalLength += currentEnd - currentStart;
28
29
+console.log(totalLength);
0 commit comments