-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolution3.js
33 lines (33 loc) · 866 Bytes
/
solution3.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
const filePath = require('path').join(__dirname, 'input');
let input = require('fs')
.readFileSync(filePath)
.toString()
.trim()
.split('\n');
const [n, atk] = input.shift().split(' ').map(BigInt);
const arr = input.map(r => r.split(' ').map(BigInt));
let left = 1n;
let right = 1000000000000000000n;
let min = 0n;
while (left <= right) {
const mid = (left + right) / 2n;
let curHp = mid;
let curAtk = atk;
for (const [t, a, h] of arr) {
if (t === 1n) {
curHp -= (h / curAtk - (h % curAtk === 0n ? 1n : 0n)) * a;
if (curHp < 1n) break;
} else {
curAtk += a;
curHp += h
if (curHp > mid) curHp = mid;
}
}
if (curHp > 0n) {
right = mid - 1n;
min = mid;
} else {
left = mid + 1n;
}
}
console.log(min.toString());