In the cube
Time limit3sMemory limit1024 MB
Place k tables on the 5001 by 5001 grid, away from the n stands, so the total of each table's distances to its c closest stands is minimal.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Bit manipulation, Sorting
- Solved
- No attempts yet
Problem

Taja likes to go to the cafe In the cube with her friends, since it has a very convenient ordering system. To place an order, a guest walks to an automated stand and chooses any dishes they like. There are several stands, and each is fixed at a specific place inside the cafe.
Guests sit in front of tables. There are tables. The th table can serve at most persons. The uncomfortableness of a table is the sum of distances from that table to the stands closest to it.
Formally, the cafe is the grid to . Each cell () can contain either one automated stand, one table, or nothing. The distance between cells and is .
Arrange the tables so that the total uncomfortableness of all tables is minimal.
Input
The first line contains two integers and (, ), the number of automated stands and the number of tables.
Each of the next lines contains the coordinates and of the th stand ().
Each of the next lines contains a single integer (), the number of seats at the th table.
Output
Output one integer, the minimal total uncomfortableness.
Hint

A possible arrangement of the tables for the first sample is shown above.