#C7651. Count Consecutive Patterns
Count Consecutive Patterns
Count Consecutive Patterns
Given n houses arranged in a line, your task is to count the number of contiguous segments (consecutive patterns) of length k that can be formed. A contiguous segment consists of houses that are adjacent to each other.
The answer is computed using the formula:
\( \text{patterns} = n - k + 1 \)
if \( k \le n \), otherwise, if \( k > n \), no such segment exists and the answer is 0.
For example, if there are 5 houses and you want to form a pattern of 2 houses, there are 4 possible segments.
inputFormat
The input is provided via stdin as two space-separated integers:
- n: The number of houses.
- k: The length of the consecutive pattern.
outputFormat
The output should be printed to stdout as a single integer denoting the number of possible contiguous segments.
## sample5 2
4