In the cube

면접 대비

시간 제한3초메모리 제한1024 MB

요약
5001x5001 격자 위에 k개의 테이블을 배치해 각 테이블에서 가장 가까운 c_i개의 거리 합을 최소로 만든다.
난이도

보통10점 중 7점

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

문제

Taja likes to go to the cafe <<In the cube>> with her friends, since it has very convenient ordering system. To make an order, guest should walk to the automated stand and choose any dishes they likes. There are several such stands and they all are fixed at specific place inside the cafe.

In the cafe guests sit in front of tables, there are kk tables. iith table cannot serve more than c_ic\_i persons. Uncomfortableness of the table position is the sum of the distances from this table to c_ic\_i automated stands closest to it.

Formally, cafe is the grid (0,0)−(5000,5000)(0, 0)-(5000, 5000). Each cell (x,y)(x, y) (0≤x,y≤5,0000 \leq x, y \leq 5\\,000) can contain either single automated stand or single table or nothing.

The distance between cells (x_1,y_1)(x\_1, y\_1) and (x_2,y_2)(x\_2, y\_2) equals to ∣x_2−x_1∣+∣y_2−y_1∣|x\_2 - x\_1| + |y\_2 - y\_1|.

You are to arrange the tables in such a way, that total sum of uncomfortablenesses for all tables should be minimal.

입력

First line of the input contains two integers nn and kk (1≤n≤181 \leq n \leq 18, 1≤k≤2001 \leq k \leq 200) --- amount of automated stands and tables correspondingly.

Following nn lines contain coordinates of iith stand: two integers x_ix\_i and y_iy\_i (0≤x_i,y_i≤5,0000 \leq x\_i, y\_i \leq 5\\, 000).

Next of each kk lines contain single integer c_jc\_j (1≤c_j≤n1 \leq c\_j \leq n) --- number of seats at jjth table.

출력

Output should contain single integer --- minimal total uncomfortableness.

힌트

Possible arrangement of the tables for the first sample looks like this:

예제2

  1. 예제 1

    입력
    3 4
    1 2
    4 1
    5 4
    1
    2
    3
    3
    
    예상 출력
    20
    
  2. 예제 2

    입력
    2 10
    0 0
    5000 5000
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    
    예상 출력
    16