In the enchanting realm of APIO, there lived a young and brilliant student named Alice. Alice had an insatiable curiosity for solving intriguing problems that challenged her mathematical prowess. One day, she stumbled upon a mystical series of numbers with a length of (that is ), and she couldn't resist the allure of exploring its secrets.
Here, she wants to share with you some of her discoveries. But before that, for your convenience, we need to define some things:
- Define as , i.e., the number of occurrences of x in .
- For a non-empty integer sequence , let denote its set of medians.
Below, Alice will show you how to calculate the set of medians step-by-step:
- First, sort the elements in ascending order to obtain the sequence . Then, .
- To enhance your understanding of the calculation of , let's consider a few examples:
- = .
- = .
- = .
Alice is eager to find the value of , where , as it poses a challenging task. The term represents the set of medians of (previously mentioned as ). Although Alice has already obtained the answer, she seeks assistance in verifying it and kindly requests your help in programming the calculation.
Implementation Details
You should implement the following procedure:
int sequence(int N, std::vector<int> A);
- : the length of sequence .
- : an array of length , describing the sequence .
- This procedure should return an integer representing the maximum value among all possible pairs .
- This procedure is called exactly once.
Example 1
Consider the following call:
sequence(7, {1, 2, 3, 1, 2, 1, 3});
This procedure should return .
In this case, , , . So the value of is .
It is easy to verify that has the greatest value among all possible pairs.
Example 2
Consider the following call:
sequence(9, {1, 1, 2, 3, 4, 3, 2, 1, 1});
This procedure should return .
Example 3
Consider the following call:
sequence(14, {2, 6, 2, 5, 3, 4, 2, 1, 4, 3, 5, 6, 3, 2});
This procedure should return .
Constraints
Subtasks
- (11 points): .
- (17 points): .
- (7 points): There exists an that satisfies , and , .
- (12 points): .
- (13 points): (for each such that ).
- (22 points): .
- (18 points): No additional constraints.
Sample Grader
The sample grader reads input in the following format:
- Line :
- Line : .
The sample grader prints your output in the following format:
- Line : the return value of
sequence
.
Attachment Package
The sample grader along with sample test cases are available here: sequence.zip.
Comments