# Maximum CPU Load Problem in a jobs list

Given a list of n Jobs with start time, end time and CPU load when it is active at any moment. If all the jobs are running at the same machine then find the maximum CPU load at any time, Also print the time at which the load was maximum.

Input: Given a list of processes with their start time and end time and the CPU load. For instance process = [0, 2, 5] has to be read as the process starts at time 0 and ends at time 2 ( end time is inclusive, means the process is still running until time 2) and it will put a load to the CPU of 5 units.

Example:

```Given Jobs: [[2, 4, 5], [0, 6, 7], [5, 10, 6]]
Maximum CPU Load is: 13 at time: 5

Given Jobs: [[2, 4, 5], [0, 6, 7], [5, 10, 6], [0, 3, 10]]
Maximum CPU Load is: 22 at time: 2
```

Approach:

Naive Solution:

Find the time at which the first task has started, call it first_time. Also, find the time at which the last task ended, call it last_time. The duration for running all the tasks would be last_time-first_time+1. Now create a count array of size duration. For each time in duration, check if for a task which starts, add or subtract the count by its load and store it in the count array (there could be multiple tasks start or end at the same time, for each task add or subtract the load in count array). Later, iterate through the count array and find the maximum.

Time Complexity: O(Duration*N)

Better Solution:

This solution is similar to Count Maximum overlaps in a given list of time intervals.

```Given Jobs: [[2, 4, 5], [0, 6, 7], [5, 10, 6], [0, 3, 10]]