Triangle Containment
Time limit4sMemory limit1024 MB
For each treasure point, sum the values of the other points strictly inside the triangle it forms with the barn wall endpoints (0,0) and (x,0).
- Level
Medium7 of 10
- Topics
- Geometry, Sorting, Segment tree
- Solved
- No attempts yet
Problem
You recently discovered there is treasure buried on your farm land. A lot of treasure! You quickly decide to put a fence around the land.
Alas, you have but a single fence post! You will have to drive to town to get more fencing material. But you can't leave the land as open as it is, so you decide to build a makeshift fence to protect some of the treasure while you are gone. You will place the post in the ground and run wire in a straight line from the post to each of two sides of your barn wall, which encloses a triangular area. The ground is very hard: only places that were dug up to bury treasure are soft enough for you to place the fence post quickly.
To figure out the best option, you first calculate the following. For each treasure in your field, suppose you place the fence post at that treasure and complete the fence as described. What is the total value of all treasures enclosed by the fence? The treasure under the post is not considered enclosed, since someone could dig around the post and reach it.

Input
The first line contains two integers () and (), where is the number of treasure points and places the two corners of the barn wall at and .
Each of the next lines contains three integers , , and (, , ), giving the location and value of one treasure point. All points are distinct. For each point, the triangle formed with the barn wall does not contain any other treasure point on its boundary.
Output
Output lines, one for each treasure point in input order. For each point, output a single integer: the total value of all points in the interior of the triangle that the point forms with the barn wall. The value of the point itself is excluded from this sum.