It Roars
Cady Heron is out in the savanna, watching the lions and birds and stuff. With her trusty camera, she wants to take as many impressive photos of animals as possible.
Animals will appear all around her at different times. The animals are quick, so if Cady doesn't take a photo of them at the perfect moment, they will run off.
As a master of nature, Cady knows exactly when and where the animals will appear. This is measured in seconds and degrees relative to her starting position ( degrees). She can only take a photo of an animal when she is facing it directly, and can only turn around at
degrees per second (in either direction).
Each animal also has a "coolness" value, , which Cady earns if she successfully snaps a photo of it.
Given the positions and timings of animals on the savanna, how can Cady maximise her total "coolness"?
Input
The first line of each test case contains an integer , the number of animals that will appear in the savanna.
The second line contains an integer , the number of degrees Cady can turn per second.
The next lines consist of three integers
,
and
, where
is the time an animal appears,
is the angle it appears at, and
is the animal's "coolness".
Output
Output the total coolness Cady can get by taking photos of animals.
Clarifications
- Cady's position is measured in degrees.
- She can turn clockwise or counterclockwise at
degrees per second.
degree clockwise of
is
degree.
degree counterclockwise of
is
degrees.
Example
Input 1
3
1
5 5 10
10 0 10
10 20 20
Output 1
20
- Cady can turn around to
degrees in
seconds and take a photo of the first animal just in time, which has
coolness.
- She can then turn back around to
degrees in
seconds and take a photo of the second animal just in time, which has
coolness.
- The last animal is not reachable.
Overall, she can collect coolness.
Input 2
4
2
1 0 20
4 5 20
7 350 40
8 10 10
Output 2
60
- First, Cady waits for
second and takes a photo of the first animal, which has
coolness.
- Next, Cady turns
degrees in
seconds to position herself at
degrees. Then, she waits
second before taking a photo of the third animal, which has
coolness.
- With this movement, Cady is unable to take a photo of the second and fourth animals.
It can be shown that is the maximum coolness Cady can collect.
Comments