Bu Dengklek owns a catfish farm.
The catfish farm is a pond consisting of an
In the pond, there are
Bu Dengklek wants to build some piers to catch the catfish.
A pier in column
Catfish
- at least one of the cells
or is covered by a pier, and - there is no pier covering cell
.
For example, consider a pond of size
- Catfish
is located at cell and weighs grams. - Catfish
is located at cell and weighs grams. - Catfish
is located at cell and weighs gram. - Catfish
is located at cell and weighs grams.
One way Bu Dengklek can build the piers is as follows:
Before the piers are built | After the piers are built |
---|---|
![]() |
![]() |
The number at a cell denotes the weight of the catfish located at the cell.
The shaded cells are covered by piers.
In this case, catfish
Bu Dengklek would like to build piers so that the total weight of catfish she can catch is as large as possible. Your task is to find the maximum total weight of catfish that Bu Dengklek can catch after building piers.
Implementation Details
You should implement the following procedure:
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y, std::vector<int> W)
: the size of the pond. : the number of catfish. , : arrays of length describing catfish locations. : array of length describing catfish weights.- This procedure should return an integer representing the maximum total weight of catfish that Bu Dengklek can catch after building piers.
- This procedure is called exactly once.
Example
Consider the following call:
max_weights(5, 4, {0, 1, 4, 3}, {2, 1, 4, 3}, {5, 2, 1, 3})
This example is illustrated in the task description above.
After building piers as described, Bu Dengklek can catch catfish
Constraints
, (for each such that ) (for each such that )- No two catfish share the same cell.
In other words,
or (for each and such that ).
Subtasks
- (3 points)
is even (for each such that ) - (6 points)
(for each such that ) - (9 points)
(for each such that ) - (14 points)
, (for each such that ) - (21 points)
- (17 points)
- (14 points) There are at most
catfish in each column. - (16 points) No additional constraints.
Sample Grader
The sample grader reads the input in the following format:
- line
: - line
:
The sample grader prints your answer in the following format:
- line
: the return value ofmax_weights
Attachment Package
The sample grader along with sample test cases are available here.
Comments
- Me after solving the problem and spending over 2 years on the implementation with too many bugs in my code to fix
Since the sample test case was improperly placed, it was moved, and all submissions were rejudged.