-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathts.ts
More file actions
33 lines (26 loc) · 882 Bytes
/
ts.ts
File metadata and controls
33 lines (26 loc) · 882 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import readlineSync from 'readline-sync'
const readline = () => readlineSync.prompt({ encoding: 'utf-8', prompt: '' })
// ------ Everything above this line will get cut when running copy script
const [speed, lightCount] = [readline(), readline()].map(x => +x)
type Light = { distance: number; duration: number }
let lights: Light[] = []
for (let i = 0; i < lightCount; i++) {
const [distance, duration] = readline()
.split(' ')
.map(x => +x)
lights.push({ distance, duration })
}
const isRed = (speed: number, light: Light) =>
(18 * light.distance) % (10 * speed * light.duration) >= 5 * speed * light.duration
let currentSpeed = speed
for (; currentSpeed > 0; --currentSpeed) {
let ok = true
for (let i = 0; i < lightCount; i++) {
if (isRed(currentSpeed, lights[i])) {
ok = false
break
}
}
if (ok) break
}
console.log(currentSpeed)