#P9690. Counting the Annual Programming Contest Occurrences
Counting the Annual Programming Contest Occurrences
Counting the Annual Programming Contest Occurrences
In a certain world, a programming contest has been held annually since year \(y_1\), except for \(n\) specific years \(s_1, s_2, \ldots, s_n\) when it was not held due to special reasons.
The task is to compute the number of times the competition has actually been held up to and including year \(y_2\). The formula to calculate the number of times the contest was held is:
[ \text{Count} = (y_2 - y_1 + 1) - \Bigl|{ s_i : y_1 \leq s_i \leq y_2 }\Bigr| ]
For example, if \(y_1 = 2003\), \(y_2 = 2023\), and there are several years when the contest was not held (such as due to the epidemic in 2020), the output should represent the total number of held contests.
Note: It is guaranteed that \(y_1 \leq y_2\).
inputFormat
The input is given in the following format:
y1 y2 n s1 s2 ... sn
Here, the first line contains two integers \(y_1\) and \(y_2\) (the starting and ending years, respectively). The second line contains an integer \(n\), representing the number of years when the contest was not held. The third line contains \(n\) distinct integers \(s_1, s_2, \ldots, s_n\) separated by spaces.
outputFormat
Output a single integer representing the number of times the single annual contest was held from year \(y_1\) to year \(y_2\) (inclusive).
sample
2003 2023
1
2020
20