Assign citizens to one of their two angularly nearest train rays, respecting each ray's capacity, and maximize the number assigned.
Hard8GreedySortingGeometryTwo pointersNo attempts yetTime limit10sMemory limit512 MBHubtown is a large Nordic city that is home to n citizens. Every morning each citizen wants to travel to the central hub the city is named after, using one of the m commuter trains that pass through the city. Each train line is a ray, a line segment that extends infinitely far in one direction, and it ends at the central hub at coordinates (0,0). A train line carries a limited number of people, and that limit may differ between lines, so a line can fill up and the citizens who do not fit drive instead. The city council wants as few people as possible to go by car. To arrange that, the council issues instructions stating which citizens may take which train.
A citizen always takes the train line of least angular distance from their house. A citizen who sits exactly in the middle between two train lines is willing to take either of them, and the council decides which of the two that citizen uses.
The figure below illustrates the first sample. The dashed arrows point at the train line each citizen is closest to. The quantity measured here is angular distance, not Euclidean distance.

Find the largest number of citizens who can reach the central hub by train in the morning, where each of those citizens takes one of the lines of least angular distance from their house and no line carries more citizens than its limit.
The first line contains two integers n and m. Here n is the number of citizens with 0≤n≤200000, and m is the number of train lines with 1≤m≤200000.
Each of the next n lines contains two integers x and y, the Cartesian coordinates of one citizen's home. No citizen lives at the central hub.
Each of the following m lines contains three integers x, y and c describing one train line. The point (x,y) is different from the central hub and the line passes through it. The capacity of the line is c with 0≤c≤n. The train line is the ray that starts at (0,0) and passes through (x,y).
Every coordinate x and y, for both the homes and the points that define the train lines, is at most 1000 in absolute value. No two train lines overlap. Several citizens may live at the same coordinates.
Print one integer, the largest number of citizens who can reach the central hub by train.