Shopping Deals

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

요약
가중치가 있는 M개 점과 각각 한 번만 쓸 수 있는 N개의 사분면 할인이 주어질 때, 모든 점을 덮는 최소 비용을 구한다.
난이도

어려움10점 중 9점

유형
그리디, 동적 계획법, 정렬, 기하
정답자
아직 제출이 없습니다

문제

You are shopping from a store that sells a total of MM items. The store layout can be modelled as a two-dimensional plane, where the ii-th item is located at the point (x_i,y_i)(x\_i , y\_i) and has a price of p_ip\_i.

The store offers NN shopping deals. The ii-th shopping deal is specified by a point (a_i,b_i)(a\_i , b\_i), and for a cost of c_ic\_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)(x, y) such that x≤a_ix ≤ a\_i and y≤b_iy ≤ b\_i.
  • The region of points (x,y)(x, y) such that x≤a_ix ≤ a\_i and y≥b_iy ≥ b\_i.
  • The region of points (x,y)(x, y) such that x≥a_ix ≥ a\_i and y≤b_iy ≤ b\_i.
  • The region of points (x,y)(x, y) such that x≥a_ix ≥ a\_i and y≥b_iy ≥ b\_i.

Each shopping deal can only be used at most once. Items can also be purchased individually by paying their respective price p_ip\_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 NN and MM.

The next N lines of input each contain three space-separated integers, a_ia\_i, b_ib\_i, and c_ic\_i (−109≤a_i,b_i≤109−10^9 ≤ a\_i , b\_i ≤ 10^9, 1≤c_i≤1091 ≤ c\_i ≤ 10^9).

The next M lines of input each contain three space-separated integers, x_ix\_i , y_iy\_i , and p_ip\_i (−109≤x_i,y_i≤109−10^9 ≤ x\_i , y\_i ≤ 10^9, 1≤p_i≤1091 ≤ 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.

예제1

  1. 예제 1

    입력
    2 4
    1 1 3
    3 3 13
    0 0 2
    0 2 5
    2 0 4
    2 2 3
    
    예상 출력
    12