Our satellite has just discovered an alien civilization on a remote planet. We have already obtained a low-resolution photo of a square area of the planet. The photo shows many signs of intelligent life. Our experts have identified
Internally, the satellite has divided the area of the low-resolution photo into an
Our satellite is on a stable orbit that passes directly over the main diagonal of the grid. The main diagonal is the line segment that connects the top left and the bottom right corner of the grid. The satellite can take a high-resolution photo of any area that satisfies the following constraints:
- the shape of the area is a square,
- two opposite corners of the square both lie on the main diagonal of the grid,
- each cell of the grid is either completely inside or completely outside the photographed area.
The satellite is able to take at most
Once the satellite is done taking photos, it will transmit the high-resolution photo of each photographed cell to our home base (regardless of whether that cell contains some points of interest). The data for each photographed cell will only be transmitted once, even if the cell was photographed several times.
Thus, we have to choose at most
- each cell containing at least one point of interest is photographed at least once, and
- the number of cells that are photographed at least once is minimized.
Your task is to find the smallest possible total number of photographed cells.
Implementation details
You should implement the following function (method):
long long take_photos(int n, int m, int k, int r[], int c[])
n
: the number of points of interest,m
: the number of rows (and also columns) in the grid,k
: the maximum number of photos the satellite can take,r
andc
: two arrays of length describing the coordinates of the grid cells that contain points of interest. For , the point of interest is located in the cell ,- the function should return the smallest possible total number of cells that are photographed at least once (given that the photos must cover all points of interest).
Examples
Example 1
take_photos(5, 7, 2, {0, 4, 4, 4, 4}, {3, 4, 6, 5, 6})
In this example we have a
One way to capture all five points of interest is to take two photos: a photo of the
The optimal solution uses one photo to capture the take_photos
should return
Note that it is sufficient to photograph the cell
This example is shown in the figures below. The leftmost figure shows the grid that corresponds to this example. The middle figure shows the suboptimal solution in which
Example 2
take_photos(2, 6, 2, {1, 4}, {4, 1})
Here we have points of interest located symmetrically: in the cells
The figures below show this example and its optimal solution. In this solution the satellite captures a single photo of
Subtasks
For all subtasks,
- (4 points)
, , , - (12 points)
, , for all such that , , - (9 points)
, , - (16 points)
, , - (19 points)
, , , - (40 points)
, .
Comments