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
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: = . = . = .
- First, sort the elements
Alice is eager to find the value of
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,
It is easy to verify that
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 ofsequence
.
Attachment Package
The sample grader along with sample test cases are available here: sequence.zip.
Comments