-
Notifications
You must be signed in to change notification settings - Fork 0
/
readInputFromNode.js
66 lines (55 loc) · 1.22 KB
/
readInputFromNode.js
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;
process.stdin.on('data', (inputStdin) => {
inputString += inputStdin;
});
process.stdin.on('end', (_) => {
inputString = inputString
.trim()
.split('\n')
.map((string) => {
return string.trim();
});
main();
});
function readline() {
return inputString[currentLine++];
}
function main() {
const firstLine = readline();
const [n, m] = firstLine.split(' ');
let weightArray = [];
for (let i = 0; i < parseInt(m); i++) {
weightArray.push(readline());
}
}
function findMaxStability(n, m, weightArray) {
let min = 1;
let max = m;
const maxStability =
Math.abs(min - max) * weightArray[0].weightArray[weightArray.length - 1];
min = 1;
max = maxStability;
let mid = 0;
while (max - min > 0) {
mid = Math.floor((min + max) / 2);
if (checkIfArangmentPossible(mid)) {
min = mid;
} else {
max = mid;
}
}
console.log(mid);
function checkIfArangmentPossible(distance) {
let orbit = 1;
let planet = 1;
while (orbit < n && planet < m) {
orbit = orbit + distance;
planet++;
}
return orbit < n ? true : false;
}
return ""
}