-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path11971.js
More file actions
21 lines (16 loc) · 797 Bytes
/
11971.js
File metadata and controls
21 lines (16 loc) · 797 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*
도로 길이가 100km밖에 안되니까 100칸짜리 배열로 처리
*/
const INPUT_FILE = process.platform === 'linux' ? '/dev/stdin' : './input';
const inputs = require('fs').readFileSync(INPUT_FILE).toString().trim()
.split('\n')
.map((line) => line.split(' ').map(Number));
const [roadSectionCount] = inputs[0];
const roadSections = inputs.slice(1, roadSectionCount + 1);
const carSections = inputs.slice(roadSectionCount + 1);
const road = [];
roadSections.forEach(([length, speedLimit]) => road.push(...new Array(length).fill(speedLimit)));
const carSpeed = [];
carSections.forEach(([length, speed]) => carSpeed.push(...new Array(length).fill(speed)));
const speedDifference = carSpeed.map((value, index) => value - road[index]);
console.log(Math.max(0, ...speedDifference));