Red and Blue Points 3
Time limit1sMemory limit1024 MB
Given red and blue points with blue powers, draw a line so all red points lie on one side, and find the maximum total power of blue points on the other side.
- Level
Medium7 of 10
- Topics
- Geometry, Sorting, Two pointers
- Solved
- No attempts yet
Problem
The plane has red points and blue points. The -th blue point has power .
The blue points have started attacking the red points. To protect themselves, the red points want to draw one straight line and set up a protected zone. They choose one of the two half-planes formed by the line. The chosen half-plane and the line itself become the protected zone, and every red point must lie inside it.
The red points cannot drive every blue point out of the zone. So they set the zone to weaken the blue points inside it as much as possible. Choose the zone so that the total power of the blue points outside it is maximized.
Input
The first line contains two positive integers and , separated by a space.
Each of the next lines contains the x and y coordinates of a red point, separated by a space.
Each of the next lines contains the x coordinate, the y coordinate, and the power of blue point , separated by spaces.
All coordinates are integers with absolute values at most . No two points share the same coordinates. No three points lie on one line.
Output
Print the maximum total power of blue points that can be placed outside the protected zone by drawing a line. If no blue point can be placed outside, print .