Minimum Segments
Given is an array consisting of n intervals. The ith interval is of type
(a[i], b[i]). Also given is an integer k. Add exactly one segment
(a, b) to the array such that b - a ≤ k and the modified array can
be separated into the minimum number of connected sets.
A set of segments (a[1], b[1]), (a[2], b[2]), ...,
(a[n], b[n]) is connected if every point in the segment
(min(a[1], a[2], ..., a[n]), max(b[1], b[2], ..., b[n])) is covered by some segment
(a[i], b[i]) in the set.
Complete the function minimumDivision in the editor.
minimumDivision has the following parameters:
- 1.
int a[n]: an integer array of first parameters of intervals - 2.
int b[n]: an integer array of second parameters of intervals - 3.
k: an integer denoting the maximum range of the segment that can be added
Returns
int: an integer denoting the minimum number of sets needed to separate the array after adding one segment.
1Example 1
Constraints
Limits and guarantees your solution can rely on.
- 1 ≤ n ≤ 2 * 105
- 1 ≤ a[i] ≤ b[i] ≤ 109
- 1 ≤ k ≤ 109