Shopping Deals

시간 제한5초메모리 제한2048 MB

문제

You are shopping from a store that sells a total of $M$ items. The store layout can be modelled as a two-dimensional plane, where the $i$-th item is located at the point $(x_i , y_i)$ and has a price of $p_i$.

The store offers $N$ shopping deals. The $i$-th shopping deal is specified by a point $(a_i , b_i)$, and for a cost of $c_i$, you can obtain one of every item within exactly one of the following four regions of your choice:

  • The region of points $(x, y)$ such that $x ≤ a_i$ and $y ≤ b_i$.
  • The region of points $(x, y)$ such that $x ≤ a_i$ and $y ≥ b_i$.
  • The region of points $(x, y)$ such that $x ≥ a_i$ and $y ≤ b_i$.
  • The region of points $(x, y)$ such that $x ≥ a_i$ and $y ≥ b_i$.

Each shopping deal can only be used at most once. Items can also be purchased individually by paying their respective price $p_i$.

You want to obtain at least one of each item in the store. Find the minimum total cost you must pay to do so.

입력

The first line of input contains two space-separated integers $N$ and $M$.

The next N lines of input each contain three space-separated integers, $a_i$, $b_i$, and $c_i$ ($−10^9 ≤ a_i , b_i ≤ 10^9$, $1 ≤ c_i ≤ 10^9$).

The next M lines of input each contain three space-separated integers, $x_i$ , $y_i$ , and $p_i$ ($−10^9 ≤ x_i , y_i ≤ 10^9$, $1 ≤ p_i ≤ 10^9$).

출력

On a single line, output the minimum total cost that you must pay to obtain at least one of each item.