interval scheduling variant: 1 machine with 2 tasks need to complete only
Let $max$ be the maximum period of the tasks we have checked so far. Let $max2$ be the maximum sum of two non-overlapping tasks we have checked so far. Both of them are 0 initially.

Sort all start times and end times of the given tasks. Iterate over them, from the smallest to largest.


A start time is encountered. If the sum of the period of the corresponding task and $max$ is greater than $max2$, update $max2$.
An end time is encountered. If the period of the corresponding task is greater than $max$, update $max$.


Now $max2$ is what we wanted. The algorithm runs in $O(n\log n)$.

The above algorithm does not specify what to do when multiple times are encountered at the same time. That part should be easy for you to fill in.