#K78497. Asteroid Impact Resistance
Asteroid Impact Resistance
Asteroid Impact Resistance
In this problem, you are given several test cases. Each test case describes a space station's maximum force capacity and a list of incoming asteroids. Each asteroid is characterized by its distance from the station, d, and its mass, m. The impact force of an asteroid is computed using the formula: $$F_i = d_i^2 \times m_i$$. The total force is the sum of the individual forces: $$F_{total} = \sum_{i=1}^n d_i^2 \times m_i$$. If the total force does not exceed the station's maximum force capacity, the station is considered SAFE; otherwise, it is in DANGER.
Your task is to determine for each test case whether the station can withstand the asteroid impacts.
inputFormat
The input begins with an integer T, the number of test cases. For each test case, the first line contains two integers: F
(the maximum allowed force) and N
(the number of asteroids). The next N lines each contain two integers d
and m
representing the distance and mass of an asteroid, respectively.
outputFormat
For each test case, output a single line containing either SAFE
if the total computed force is less than or equal to F, or DANGER
otherwise.## sample
2
5000 3
10 20
5 25
15 5
10000 2
20 2
30 10
SAFE
SAFE
</p>