There are
For some positive interference value
- tower
is to the left of tower and tower is to the right of tower , that is, , and - the heights of tower
and tower are both at most metres.
Pak Dengklek wants to lease some radio towers for his new radio network.
Your task is to answer
- Pak Dengklek can only lease towers with indices between
and (inclusive), and - the interference value
is , and - any pair of radio towers that Pak Dengklek leases must be able to communicate with each other.
Note that two leased towers may communicate using an intermediary tower
Implementation Details
You should implement the following procedures:
void init(int N, std::vector<int> H)
: the number of radio towers. : an array of length describing the tower heights.- This procedure is called exactly once, before any calls to
max_towers
.
int max_towers(int L, int R, int D)
, : the boundaries of a range of towers. : the value of .- This procedure should return the maximum number of radio towers Pak Dengklek can lease for his new radio network if he is only allowed to lease towers between tower
and tower (inclusive) and the value of is . - This procedure is called exactly
times.
Example
Consider the following sequence of calls:
init(7, [10, 20, 60, 40, 50, 30, 70])
max_towers(1, 5, 10)
Pak Dengklek can lease towers
Towers
max_towers(2, 2, 100)
There is only
max_towers(0, 6, 17)
Pak Dengklek can lease towers
Constraints
(for each such that ) (for each and such that )
Subtasks
- (4 points) There exists a tower
such that- for each
such that : , and - for each
such that : .
- for each
- (11 points)
, - (12 points)
- (14 points)
- (17 points)
, - (19 points) The value of
is the same across allmax_towers
calls. - (23 points) No additional constraints.
Sample Grader
The sample grader reads the input in the following format:
- line
: - line
: - line
: for question
The sample grader prints your answers in the following format:
- line
: the return value ofmax_towers
for question
Attachment Package
The sample grader along with sample test cases are available here.
Comments