Under construction

Still being built. Things may change

Red and Blue Points 3

Time limit1sMemory limit1024 MB

Summary
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 NN red points and MM blue points. The ii-th blue point has power BiB_i.

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 NN and MM, separated by a space. (1≤N,M≤200000)(1 \le N, M \le 200000)

Each of the next NN lines contains the x and y coordinates of a red point, separated by a space.

Each of the next MM lines contains the x coordinate, the y coordinate, and the power BiB_i of blue point ii, separated by spaces. (1≤Bi≤109)(1 \le B_i \le 10^9)

All coordinates are integers with absolute values at most 10910^9. 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 00.

Examples2

  1. Example 1

    Input
    4 2
    2 2
    2 4
    4 2
    4 4
    5 3 1
    1 3 2
    
    Expected output
    2
    
  2. Example 2

    Input
    1 1
    1 1
    2 2 1
    
    Expected output
    1