Banshee
시간 제한1초메모리 제한1024 MB
밴시가 좌표 0에서 출발해 모든 건물 구간을 파괴해야 할 때, 이동, 쿨다운, 피해, 보호막 재충전 규칙을 고려한 최소 시간을 구한다.
문제
You are playing matchup Terran vs. Protoss in StarCraft II and the game came to elimination, which can be simplified to one-dimensional setting.
You have the army consisting of bashees with upgraded hyperflight rotors, located at point on a coordinate line. Your opponent has buildings located on the positive half of the line. Each building is regarded as a segment.
Here are movement rules for banshees:
- A banshee with upgraded hyperflight rotors has a speed of units per second. Acceleration is immediate.
- There is no unit collision for flying units in StarCraft, so any number of banshees can be located at the same point.
Next are the attack rules:
- A banshee can attack a target within a range of units. A building can be attacked if any of its points is within the range.
- For simplicity, an attack goes as follows. First, the banshee has to wait without moving, for the whole cooldown time of seconds. After that, it fires projectiles which immediately damage the target. This is the closest analogy of charging your weapons before the shot. Note that it is different from the actual StarCraft mechanics.
- In each attack, a banshee attacks one target and fires two projectiles at once. Each projectile deals damage.
Finally, here are defense rules:
- Initially, each building has full hitpoints and full shields. A building is destroyed if its hitpoints drop to zero or below.
- If a building is damaged but not destroyed, and seconds pass without taking damage, its shields begin to recharge. Such building recovers shields per second until its shields are full or it is attacked again. The recovery is continuous: for example, shields are recovered in seconds.
- Assume a building has hitpoints and shields, and receives damage . First, shields absorb all the damage they can: they are decreased by . Then, hitpoints are decreased by the remaining damage, .
You are given the initial position in this game. What is the minimal time required to eliminate all Protoss buildings?
입력
You will be given multiple test cases in this problem.
The first line contains a single integer , the number of test cases. Then, you will be given test cases in the format below.
The first line of each test case contains two integers and (, ): the number of remaining Protoss buildings and the number of your banshees. All your banshees are initially located at point of the line.
Each of the following lines contains four integers , , , (, , ): the left and right endpoints of the building, its hitpoints and its shields, respectively. You may assume that buildings don't overlap and are given in the order of increasing their coordinate.
The sum of over all test cases is at most .
출력
For each test case, output the only number on a separate line: the minimal time required to eliminate all Protoss buildings. Your answer would be considered correct if its absolute difference with the jury's answer is at most .