#K47342. Total Active Time
Total Active Time
Total Active Time
You are given a list of time intervals representing the periods during which an employee was active. Each interval is given as a pair of integers \( (start, end) \), which denotes that the employee started working at time start and finished at time end. The intervals might overlap. Your task is to compute the total active working time of the employee, counting overlapped intervals only once. For example, if the intervals are \( (1, 3) \) and \( (2, 5) \), the overlapped period should be counted only once, and the total active time is \(5 - 1 = 4\) (if there were no merges, but there is an example provided below).
Note: The duration of an interval \( (start, end) \) is defined as \( end - start \). If there are no intervals, the active time is 0.
Examples:
- Input:
3\n1 3\n2 5\n4 6
→ Output:5
- Input:
3\n1 2\n3 4\n5 6
→ Output:3
inputFormat
The input is read from standard input (stdin). The first line contains an integer \( n \), the number of intervals. Each of the following \( n \) lines contains two integers separated by a space representing the start and end times of an interval. If \( n = 0 \), it means no intervals are provided.
outputFormat
Output a single integer to standard output (stdout) which represents the total active working time after merging overlapping intervals.
## sample3
1 3
2 5
4 6
5