You are given a set of tasks, each defined by a start time, an end time, and a resource demand (a positive integer). All tasks consume the resource continuously from their start time (inclusive) to their end time (exclusive). At any moment, the total resource usage is the sum of the demands of all tasks that are active at that moment.
Your task is to solve the following two parts:
peak.peak. Return these intervals as a list of [start, end) pairs, sorted by start time, with no overlaps.Function specification:
maximumPeakIntervals(tasks), where tasks is a list of n tasks (n is the number of tasks); each task is a list of three integers [start, end, demand].Return value:
(peak, intervals), where peak is the integer maximum usage and intervals is the list of k peak intervals, each a pair [start, end].(The example outputs below show this as peak, then k, then one interval per line.)
Example 1:
Input:
3
1 4 5
2 5 3
3 6 2
Output:
10
1
3 4
Explanation: At time 3, all three tasks are active (demands 5+3+2=10), achieving the peak. This peak lasts from time 3 to 4 (when the first task ends). Hence the interval [3, 4).
tasks = [[1, 4, 5], [2, 5, 3], [3, 6, 2]]10 1 3 4
We have three tasks with start, end, and demand.
Example 2:
Input:
4
1 3 5
2 4 2
5 7 3
6 8 4
Output:
7
2
2 3
6 7
Explanation: The peak demand 7 appears in two separate periods: [2,3) (tasks 1 and 2) and [6,7) (tasks 3 and 4).
Example 3:
Input:
1
1 5 10
Output:
10
1
1 5
Explanation: Only one task; its demand is the peak, and the interval is its entire active duration.
Constraints:
1 <= n <= 200,0001 <= start < end <= 10^91 <= demand <= 10^9Input:
1
1 3 10
Output:
10
1
1 3
tasks = [[1, 4, 5], [2, 5, 3], [3, 6, 2]]10 1 3 4
We have three tasks with start, end, and demand.