#P1496. Calculate Total Burning Length
Calculate Total Burning Length
Calculate Total Burning Length
You are given N intervals representing the burning regions. Each interval is defined by its start and end positions. The intervals may overlap. Your task is to compute the total length of the burned area, i.e., the length covered by the union of these intervals.
Note: The length of an interval defined by [a, b] is computed as b - a.
Input Format: The first line of input contains a single integer N, the number of intervals. Each of the next N lines contains two space-separated integers representing the start and end of an interval.
Output Format: Output a single integer representing the total burning length.
inputFormat
The input is given as follows:
- The first line contains an integer N (the number of intervals).
- Each of the following N lines contains two integers start and end separated by a space representing an interval.
outputFormat
Output a single integer which is the sum of the lengths of the union of all intervals.
sample
3
1 3
2 6
8 10
7