In the cube
면접 대비시간 제한3초메모리 제한1024 MB
5001x5001 격자 위에 k개의 테이블을 배치해 각 테이블에서 가장 가까운 c_i개의 거리 합을 최소로 만든다.
문제
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 tables. th table cannot serve more than persons. Uncomfortableness of the table position is the sum of the distances from this table to automated stands closest to it.
Formally, cafe is the grid . Each cell () can contain either single automated stand or single table or nothing.
The distance between cells and equals to .
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 and (, ) --- amount of automated stands and tables correspondingly.
Following lines contain coordinates of th stand: two integers and ().
Next of each lines contain single integer () --- number of seats at th table.
출력
Output should contain single integer --- minimal total uncomfortableness.
힌트
Possible arrangement of the tables for the first sample looks like this:
