Skip to content

Commit

Permalink
#19 23.09.04 > 5 > 선 긋기
Browse files Browse the repository at this point in the history
  • Loading branch information
beurmuz committed Sep 4, 2023
1 parent bfbe359 commit ab4a564
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/bj/gold/5/2170.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"use strict";

const fs = require("fs");
const filePath = process.platform === "linux" ? "/dev/stdin" : "input.txt";
let input = fs.readFileSync(filePath).toString().trim().split("\n");

let n = Number(input[0]);
let arr = new Array(n);
for (let i = 0; i < n; i++) {
let [a, b] = input[i + 1].split(" ").map(Number);
arr[i] = [a, b];
}
arr.sort((a, b) => a[0] - b[0]);

let ans = 0;
ans += arr[0][1] - arr[0][0];
let cur = arr[0][1];
for (let i = 1; i < n; i++) {
if (arr[i][0] <= cur && arr[i][1] > cur) {
ans += arr[i][1] - cur;
cur = arr[i][1];
}
if (arr[i][0] > cur) {
ans += arr[i][1] - arr[i][0];
cur = arr[i][1];
}
}
console.log(ans);
1 change: 1 addition & 0 deletions src/bj/gold/5/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@
| 26 | 2467 | [용액](./2467.js) | 23.08.11 ||
| 27 | 1759 | [암호 만들기](./1759.js) | 23.08.24 | O |
| 29 | 16987 | [계란으로 계란치기](./16987.js) | 23.08.28 | X 모르것써요 |
| 30 | 2170 | [선 긋기](./2170.js) | 23.09.04 | X |

0 comments on commit ab4a564

Please sign in to comment.