proc to store the start and end times of events along with their values.proc: one for the start time and one for the end time (incremented by 1 to account for inclusivity).proc list by time.ans to 0 and m to 0, where m represents the maximum value of any event that has ended so far.proc list:
a. If the current tuple represents the start of an event, update ans to be the maximum of ans and m + val.
b. If the current tuple represents the end of an event, update m to be the maximum of m and val.ans as the maximum sum of two non-overlapping events.