Time Limit: 2000/1000 MS (Java/Others)

Memory Limit: 32768/32768 K (Java/Others)

It’s harvest season now!

Farmer John plants a lot of corn. There are many birds living around his corn field. These birds keep stealing his corn all the time. John can't stand with that any more. He decides to put some scarecrows in the field to drive the birds away.

John's field can be considered as an N×N grid which has N×N intersections. John plants his corn on every intersection at first. But as time goes by, some corn were destroyed by rats or birds so some vacant intersections were left. Now John wants to put scarecrows on those vacant intersections and he can put at most one scarecrow on one intersection. Because of the landform and the different height of corn, every vacant intersections has a scaring range R meaning that if John put a scarecrow on it, the scarecrow can only scare the birds inside the range of manhattan distance R from the intersection.

The figure above shows a 7×7 field. Assuming that the scaring range of vacant intersection (4,2) is 2, then the corn on the marked intersections can be protected by a scarecrow put on intersection (4,2).

Now John wants to figure out at least how many scarecrows he must buy to protect all his corn.

Farmer John plants a lot of corn. There are many birds living around his corn field. These birds keep stealing his corn all the time. John can't stand with that any more. He decides to put some scarecrows in the field to drive the birds away.

John's field can be considered as an N×N grid which has N×N intersections. John plants his corn on every intersection at first. But as time goes by, some corn were destroyed by rats or birds so some vacant intersections were left. Now John wants to put scarecrows on those vacant intersections and he can put at most one scarecrow on one intersection. Because of the landform and the different height of corn, every vacant intersections has a scaring range R meaning that if John put a scarecrow on it, the scarecrow can only scare the birds inside the range of manhattan distance R from the intersection.

The figure above shows a 7×7 field. Assuming that the scaring range of vacant intersection (4,2) is 2, then the corn on the marked intersections can be protected by a scarecrow put on intersection (4,2).

Now John wants to figure out at least how many scarecrows he must buy to protect all his corn.

There are several test cases.

For each test case:

The first line is an integer N ( 2 <= N <= 50 ) meaning that John's field is an N×N grid.

The second line is an integer K ( 0<= K <= 10) meaning that there are K vacant intersections on which John can put a scarecrow.

The third line describes the position of K vacant intersections, in the format of r_{1},c_{1},r_{2},c_{2} …. r_{K},c_{k} . (r_{i},c_{i}) is the position of the i-th intersection and 1 <= r_{1},c_{1},r_{2},c_{2} …. r_{K},c_{k} <= N.

The forth line gives the scaring range of all vacant intersections, in the format of R_{1},R_{2}…R_{K} and 0 <= R_{1},R_{2}…R_{K} <= 2 × N.

The input ends with N = 0.

For each test case:

The first line is an integer N ( 2 <= N <= 50 ) meaning that John's field is an N×N grid.

The second line is an integer K ( 0<= K <= 10) meaning that there are K vacant intersections on which John can put a scarecrow.

The third line describes the position of K vacant intersections, in the format of r

The forth line gives the scaring range of all vacant intersections, in the format of R

The input ends with N = 0.

提交代码