#C3505. Minimum Additional Toy Deliveries
Minimum Additional Toy Deliveries
Minimum Additional Toy Deliveries
You are given a city with \(n\) houses numbered from 1 to \(n\). There are currently some toy deliveries, and each delivery covers all houses in a contiguous interval \([a, b]\). Your task is to compute the minimum number of additional deliveries required so that every house receives at least one toy.
Details:
- The first line of input contains two integers \(n\) and \(m\), representing the number of houses and the number of existing deliveries respectively.
- Each of the following \(m\) lines contains two integers \(a\) and \(b\) (with \(1 \leq a \leq b \leq n\)) indicating that houses from \(a\) to \(b\) (inclusive) have already received a toy.
Your goal is to determine how many houses have not received a toy, i.e. the number of additional deliveries needed if each delivery covers exactly one uncovered house.
inputFormat
The input is given from standard input (stdin) in the following format:
n m a1 b1 a2 b2 ... am bm
Where:
- \(n\) is the total number of houses.
- \(m\) is the number of existing deliveries.
- Each delivery is specified by two integers \(a_i\) and \(b_i\), representing that houses from \(a_i\) to \(b_i\) are already covered.
outputFormat
Output a single integer to standard output (stdout) representing the minimum number of additional deliveries required so that every house receives at least one toy.
## sample7 3
1 3
4 5
6 7
0