Solar Energy
Time limit9sMemory limit1024 MB
Given N stars each contributing a clipped triangular amount of energy as a function of launch angle, find the angle maximizing the total contribution.
- Level
Hard8 of 10
- Topics
- Geometry, Sorting, Prefix sum, Binary search
- Solved
- No attempts yet
Problem
You are planning to travel in interstellar space in the hope of finding habitable planets. You have already identified stars that can recharge your spaceship via its solar panels. The only work left is to decide the orientation of the spaceship that maximizes the distance it can travel.
Space is modeled as a 2D plane, with the Earth at the origin. The spaceship can be launched from the Earth in a straight line, in any direction. Star can provide enough energy to travel distance if the spaceship is launched at an angle of with the -axis. If the angle is not perfectly aligned, then the spaceship gets less energy. Specifically, if the launch direction makes an angle of with the -axis, then it gets enough energy to travel distance of
[\max(0, T_i - s_i \cdot \mathrm{dist}(a_i, a))]
from star , where is the minimum radians needed to go from angle to . The distance that the spaceship can travel is simply the sum of the distances that each star contributes. Find the maximum distance that the starship can travel.
Input
The first line contains the value , . Following this are lines each containing three real numbers , , and , with , , and . All real numbers in the input have at most digits after the decimal point.
Output
On a single line output the maximum distance the spacecraft can travel. Your answer is considered correct if it has an absolute or relative error of at most .