Within Arm's Reach
Time limit2sMemory limit512 MB
Given segment lengths of a planar robotic arm and a target point, find where the tip lands when bent as close to the target as possible.
- Level
Medium5 of 10
- Topics
- Geometry, Math, Implementation
- Solved
- No attempts yet
Problem
Joao wants to join his university's robot soccer team. He knows little about robotics or mathematics yet, so he decided to build a two dimensional robotic arm first and learn from it.
The arm is made of segments. One end of the first segment is pinned to the origin, and one end of segment is joined to the far end of segment . Any angle between two neighboring segments is allowed, including angles that make the arm look like it overlaps itself when seen from above. Bending the arm never changes a segment length.
The free end of segment is the tip of the arm. Given the segment lengths and a target point, find where the tip sits when the arm is bent so that the tip is as close to the target as possible.
Several configurations can tie for the smallest distance, but they all put the tip on the same point. There is one exception. If the target is the origin and the tip cannot reach the origin, the closest points form a full circle, and then the answer is the configuration that puts the tip on the positive axis, so the answer has and .
Input
The first line contains , the number of segments. Each of the next lines contains , the length of the -th segment counted from the origin toward the tip. The last line contains the coordinates and of the target, separated by a space.
Output
Print the coordinates and of the tip on one line, rounded to three decimal places and separated by a space. Print a coordinate that rounds to zero as 0.000, not as -0.000.
Limits
- : the number of segments in the arm
- : the length of the -th segment
- : the coordinates of the target
Every input value is an integer.
Figure

The figure shows the case with segment lengths 5, 3, 4 and target . The circled cross marks the target, and the square marks the end pinned to the origin.