#C7641. Treasure Hunt in a Grid

    ID: 51535 Type: Default 1000ms 256MiB

Treasure Hunt in a Grid

Treasure Hunt in a Grid

In this problem, you are given an N×NN \times N grid that contains treasures and obstacles. You start at a given position and are allowed to move at most LL steps. Each move can take you up, down, left, or right. When you land on a cell containing a treasure, you collect it (and it is then removed from the grid). However, you cannot move into cells that contain obstacles. Your task is to determine the maximum number of treasures that can be collected within the allowed number of moves.

inputFormat

The input is read from standard input (stdin) and consists of four lines:

Line 1: Four integers NN, MM, KK, LL, where NN is the grid size (the grid is N×NN \times N), MM is the number of treasures, KK is the number of obstacles, and LL is the maximum number of moves allowed.

Line 2: Two integers representing the starting coordinates (sx,sy)(sx, sy).

Line 3: If M>0M > 0, this line contains 2M2M integers representing the positions of treasures in the format: t1x t1y t2x t2y t_{1x}\ t_{1y}\ t_{2x}\ t_{2y}\ \ldots. If M=0M = 0, this line will be empty.

Line 4: If K>0K > 0, this line contains 2K2K integers representing the positions of obstacles in the same format. If K=0K = 0, this line will be empty.

outputFormat

Output a single integer on standard output (stdout) representing the maximum number of treasures that can be collected.## sample

5 3 2 10
1 1
3 3 4 4 5 5
3 1 4 2
3

</p>