Shopping Deals
시간 제한5초메모리 제한2048 MB
가중치가 있는 M개 점과 각각 한 번만 쓸 수 있는 N개의 사분면 할인이 주어질 때, 모든 점을 덮는 최소 비용을 구한다.
문제
You are shopping from a store that sells a total of items. The store layout can be modelled as a two-dimensional plane, where the -th item is located at the point and has a price of .
The store offers shopping deals. The -th shopping deal is specified by a point , and for a cost of , you can obtain one of every item within exactly one of the following four regions of your choice:
- The region of points such that and .
- The region of points such that and .
- The region of points such that and .
- The region of points such that and .
Each shopping deal can only be used at most once. Items can also be purchased individually by paying their respective price .
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 and .
The next N lines of input each contain three space-separated integers, , , and (, ).
The next M lines of input each contain three space-separated integers, , , and (, ).
출력
On a single line, output the minimum total cost that you must pay to obtain at least one of each item.